From 28715c92b8234a07cbfd336f2a314889b8e1ddfc Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 30 Jul 2023 15:08:59 +0200 Subject: [PATCH] readutmp: Improve comments. Fix module description. * lib/readutmp.h (extract_trimmed_name): Add specification comment. (read_utmp): Move specification comment from lib/readutmp.c to here. Mention also UTMP_FILE and READ_UTMP_USER_PROCESS. * lib/readutmp.c (extract_trimmed_name): Fix comment. * modules/readutmp (Include): Only include the .h file if HAVE_UTMPX_H || HAVE_UTMP_H. --- ChangeLog | 10 ++++++++++ lib/readutmp.c | 9 +-------- lib/readutmp.h | 11 +++++++++++ modules/readutmp | 4 +++- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4d64fa6572..01f8981775 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2023-07-30 Bruno Haible + + readutmp: Improve comments. Fix module description. + * lib/readutmp.h (extract_trimmed_name): Add specification comment. + (read_utmp): Move specification comment from lib/readutmp.c to here. + Mention also UTMP_FILE and READ_UTMP_USER_PROCESS. + * lib/readutmp.c (extract_trimmed_name): Fix comment. + * modules/readutmp (Include): Only include the .h file if + HAVE_UTMPX_H || HAVE_UTMP_H. + 2023-07-29 Paul Eggert readutmp: work around glibc utmpx bug diff --git a/lib/readutmp.c b/lib/readutmp.c index cfc8b69c03..acffe1000e 100644 --- a/lib/readutmp.c +++ b/lib/readutmp.c @@ -40,7 +40,7 @@ # pragma GCC diagnostic ignored "-Wsizeof-pointer-memaccess" #endif -/* Copy UT->ut_name into storage obtained from malloc. Then remove any +/* Copy UT_USER (UT) into storage obtained from malloc. Then remove any trailing spaces from the copy, NUL terminate it, and return the copy. */ char * @@ -77,13 +77,6 @@ desirable_utmp_entry (STRUCT_UTMP const *u, int options) return true; } -/* Read the utmp entries corresponding to file FILE into freshly- - malloc'd storage, set *UTMP_BUF to that pointer, set *N_ENTRIES to - the number of entries, and return zero. If there is any error, - return -1, setting errno, and don't modify the parameters. - If OPTIONS & READ_UTMP_CHECK_PIDS is nonzero, omit entries whose - process-IDs do not currently exist. */ - #ifdef UTMP_NAME_FUNCTION static void diff --git a/lib/readutmp.h b/lib/readutmp.h index bf2437e02a..d4a3d3dd08 100644 --- a/lib/readutmp.h +++ b/lib/readutmp.h @@ -212,10 +212,21 @@ enum READ_UTMP_USER_PROCESS = 2 }; +/* Return a copy of UT_USER (UT), without trailing spaces, + as a freshly allocated string. */ char *extract_trimmed_name (const STRUCT_UTMP *ut) _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_RETURNS_NONNULL; +/* Read the utmp entries corresponding to file FILE into freshly- + malloc'd storage, set *UTMP_BUF to that pointer, set *N_ENTRIES to + the number of entries, and return zero. If there is any error, + return -1, setting errno, and don't modify the parameters. + A good candidate for FILE is UTMP_FILE. + If OPTIONS & READ_UTMP_CHECK_PIDS is nonzero, omit entries whose + process-IDs do not currently exist. + If OPTIONS & READ_UTMP_USER_PROCESS is nonzero, omit entries which + do not correspond to a user process. */ /* FIXME: This header should use idx_t, not size_t. */ int read_utmp (char const *file, size_t *n_entries, STRUCT_UTMP **utmp_buf, int options); diff --git a/modules/readutmp b/modules/readutmp index 2a4a4ffc68..7f84f189ea 100644 --- a/modules/readutmp +++ b/modules/readutmp @@ -25,7 +25,9 @@ lib_SOURCES += readutmp.c endif Include: -"readutmp.h" +#if HAVE_UTMPX_H || HAVE_UTMP_H +#include "readutmp.h" +#endif License: GPL -- 2.39.5