Add functions to get system user names, group names
authorDmitry Antipov <dmantipov@yandex.ru>
Tue, 17 Apr 2012 01:29:58 +0000 (21:29 -0400)
committerGlenn Morris <rgm@gnu.org>
Tue, 17 Apr 2012 01:29:58 +0000 (21:29 -0400)
Note from committer:
I removed the part that adds grp.h to AC_CHECK_HEADERS and

+#ifdef HAVE_GRP_H
 #include <grp.h>
+#endif

to src/dired.c, because the latter has unconditionally included grp.h
since 2003, and uses it eg in stat_gname.

* configure.in (AC_CHECK_FUNCS): Add getpwent, endpwent, getgrent, endgrent.

* src/dired.c (Fsystem_users, Fsystem_groups): New functions.
(syms_of_dired): Add them.

Fixes: debbugs:7900

ChangeLog
configure.in
src/ChangeLog
src/dired.c

index 8d551e0..a7da9e1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2012-04-17  Dmitry Antipov  <dmantipov@yandex.ru>
+
+       * configure.in (AC_CHECK_FUNCS):
+       Add getpwent, endpwent, getgrent, endgrent. (Bug#7900)
+
 2012-04-16  Glenn Morris  <rgm@gnu.org>
 
        * configure.in (NS_HAVE_NSINTEGER): Remove unnecessary variable.
index fd1327e..c9f0cd7 100644 (file)
@@ -2736,6 +2736,7 @@ __fpending mblen mbrlen mbsinit strsignal setitimer ualarm \
 sendto recvfrom getsockopt setsockopt getsockname getpeername \
 gai_strerror mkstemp getline getdelim mremap fsync sync \
 difftime mempcpy mblen mbrlen posix_memalign \
+getpwent endpwent getgrent endgrent \
 cfmakeraw cfsetspeed copysign __executable_start)
 
 dnl Cannot use AC_CHECK_FUNCS
index e321a70..bcb2ede 100644 (file)
@@ -1,3 +1,8 @@
+2012-04-17  Dmitry Antipov  <dmantipov@yandex.ru>
+
+       * dired.c (Fsystem_users, Fsystem_groups): New functions.  (Bug#7900)
+       (syms_of_dired): Add them.
+
 2012-04-16  Paul Eggert  <eggert@cs.ucla.edu>
 
        Fix minor alloc.c problems found by static checking.
index 9b0f94a..2c634b9 100644 (file)
@@ -1015,6 +1015,45 @@ Comparison is in lexicographic order and case is significant.  */)
   return Fstring_lessp (Fcar (f1), Fcar (f2));
 }
 \f
+
+DEFUN ("system-users", Fsystem_users, Ssystem_users, 0, 0, 0,
+       doc: /* Return a list of user names currently registered in the system.
+The value may be nil if not supported on this platform.  */)
+     (void)
+{
+  Lisp_Object users = Qnil;
+#if defined(HAVE_GETPWENT) && defined(HAVE_ENDPWENT)
+  struct passwd *pw;
+
+  while ((pw = getpwent ()))
+    users = Fcons (DECODE_SYSTEM (build_string (pw->pw_name)), users);
+
+  endpwent ();
+#endif
+  if (EQ (users, Qnil))
+    /* At least current user is always known. */
+    users = Fcons (Vuser_real_login_name, Qnil);
+  return users;
+}
+
+DEFUN ("system-groups", Fsystem_groups, Ssystem_groups, 0, 0, 0,
+       doc: /* Return a list of user group names currently registered in the system.
+The value may be nil if not supported on this platform.  */)
+     (void)
+{
+  Lisp_Object groups = Qnil;
+#if defined(HAVE_GETGRENT) && defined(HAVE_ENDGRENT)
+  struct group *gr;
+  int length;
+
+  while ((gr = getgrent ()))
+    groups = Fcons (DECODE_SYSTEM (build_string (gr->gr_name)), groups);
+
+  endgrent ();
+#endif
+  return groups;
+}
+
 void
 syms_of_dired (void)
 {
@@ -1032,6 +1071,8 @@ syms_of_dired (void)
   defsubr (&Sfile_name_all_completions);
   defsubr (&Sfile_attributes);
   defsubr (&Sfile_attributes_lessp);
+  defsubr (&Ssystem_users);
+  defsubr (&Ssystem_groups);
 
   DEFVAR_LISP ("completion-ignored-extensions", Vcompletion_ignored_extensions,
               doc: /* Completion ignores file names ending in any string in this list.