This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: FreeBSD port (52): platform dependent utmp comparison
> But since the function is used only in one module,
> make it an internal sysdeps header file that defines a static function,
> instead of an additional module that is from sysdeps.
OK, here is a patch to that effect. Plus a fix to make setutent() work
on platforms without HAVE_UT_TYPE.
2002-09-17 Bruno Haible <bruno@clisp.org>
* sysdeps/generic/utmp-equal.h: New file, extracted from utmp_file.c.
* sysdeps/generic/utmp_file.c (setutent_file): Invalidate last_entry
also on platforms with !HAVE_UT_TYPE.
(proc_utmp_eq): Remove function.
(internal_getut_r, pututline_file): Call __utmp_equal instead.
diff -r -c3 glibc-20020910.bak/sysdeps/generic/utmp_file.c glibc-20020910/sysdeps/generic/utmp_file.c
*** glibc-20020910.bak/sysdeps/generic/utmp_file.c Mon Aug 26 15:49:59 2002
--- glibc-20020910/sysdeps/generic/utmp_file.c Tue Sep 17 02:22:06 2002
***************
*** 28,33 ****
--- 28,34 ----
#include <utmp.h>
#include "utmp-private.h"
+ #include "utmp-equal.h"
/* Descriptor for the file and position. */
***************
*** 148,156 ****
__lseek64 (file_fd, 0, SEEK_SET);
file_offset = 0;
- #if _HAVE_UT_TYPE - 0
/* Make sure the entry won't match. */
last_entry.ut_type = -1;
#endif
return 1;
--- 149,162 ----
__lseek64 (file_fd, 0, SEEK_SET);
file_offset = 0;
/* Make sure the entry won't match. */
+ #if _HAVE_UT_TYPE - 0
last_entry.ut_type = -1;
+ #else
+ last_entry.ut_line[0] = '\177';
+ # if _HAVE_UT_ID - 0
+ last_entry.ut_id[0] = '\0';
+ # endif
#endif
return 1;
***************
*** 200,232 ****
static int
- proc_utmp_eq (const struct utmp *entry, const struct utmp *match)
- {
- return
- (
- #if _HAVE_UT_TYPE - 0
- (entry->ut_type == INIT_PROCESS
- || entry->ut_type == LOGIN_PROCESS
- || entry->ut_type == USER_PROCESS
- || entry->ut_type == DEAD_PROCESS)
- &&
- (match->ut_type == INIT_PROCESS
- || match->ut_type == LOGIN_PROCESS
- || match->ut_type == USER_PROCESS
- || match->ut_type == DEAD_PROCESS)
- &&
- #endif
- #if _HAVE_UT_ID - 0
- (entry->ut_id[0] && match->ut_id[0]
- ? strncmp (entry->ut_id, match->ut_id, sizeof match->ut_id) == 0
- : strncmp (entry->ut_line, match->ut_line, sizeof match->ut_line) == 0)
- #else
- strncmp (entry->ut_line, match->ut_line, sizeof match->ut_line) == 0
- #endif
- );
- }
-
- static int
internal_getut_r (const struct utmp *id, struct utmp *buffer)
{
int result = -1;
--- 206,211 ----
***************
*** 275,281 ****
}
file_offset += sizeof (struct utmp);
! if (proc_utmp_eq (buffer, id))
break;
}
}
--- 254,260 ----
}
file_offset += sizeof (struct utmp);
! if (__utmp_equal (buffer, id))
break;
}
}
***************
*** 390,396 ****
|| last_entry.ut_type == NEW_TIME))
||
#endif
! proc_utmp_eq (&last_entry, data)))
found = 1;
else
found = internal_getut_r (data, &buffer);
--- 369,375 ----
|| last_entry.ut_type == NEW_TIME))
||
#endif
! __utmp_equal (&last_entry, data)))
found = 1;
else
found = internal_getut_r (data, &buffer);
*** /dev/null Fri Sep 20 02:00:52 2002
--- glibc-20020910/sysdeps/generic/utmp-equal.h Sat Sep 14 21:37:09 2002
***************
*** 0 ****
--- 1,52 ----
+ /* Copyright (C) 1996-1999,2000-2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>
+ and Paul Janzen <pcj@primenet.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+ #include <string.h>
+ #include <utmp.h>
+
+ #include "utmp-private.h"
+
+ /* Test whether two entries match. */
+ static int
+ __utmp_equal (const struct utmp *entry, const struct utmp *match)
+ {
+ return
+ (
+ #if _HAVE_UT_TYPE - 0
+ (entry->ut_type == INIT_PROCESS
+ || entry->ut_type == LOGIN_PROCESS
+ || entry->ut_type == USER_PROCESS
+ || entry->ut_type == DEAD_PROCESS)
+ &&
+ (match->ut_type == INIT_PROCESS
+ || match->ut_type == LOGIN_PROCESS
+ || match->ut_type == USER_PROCESS
+ || match->ut_type == DEAD_PROCESS)
+ &&
+ #endif
+ #if _HAVE_UT_ID - 0
+ (entry->ut_id[0] && match->ut_id[0]
+ ? strncmp (entry->ut_id, match->ut_id, sizeof match->ut_id) == 0
+ : strncmp (entry->ut_line, match->ut_line, sizeof match->ut_line) == 0)
+ #else
+ strncmp (entry->ut_line, match->ut_line, sizeof match->ut_line) == 0
+ #endif
+ );
+ }