diff options
| author | Dmitry Antipov | 2012-04-16 21:29:58 -0400 |
|---|---|---|
| committer | Glenn Morris | 2012-04-16 21:29:58 -0400 |
| commit | 316411f0f20d409ec24ee892393f15701b05de1c (patch) | |
| tree | db48481dff396a640011c69f51bb9c98ad5034b9 /src | |
| parent | 41f03f4da76827e8611267ee5283a5df8071a617 (diff) | |
| download | emacs-316411f0f20d409ec24ee892393f15701b05de1c.tar.gz emacs-316411f0f20d409ec24ee892393f15701b05de1c.zip | |
Add functions to get system user names, group names
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 5 | ||||
| -rw-r--r-- | src/dired.c | 41 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index e321a70d4c3..bcb2edee96f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2012-04-17 Dmitry Antipov <dmantipov@yandex.ru> | ||
| 2 | |||
| 3 | * dired.c (Fsystem_users, Fsystem_groups): New functions. (Bug#7900) | ||
| 4 | (syms_of_dired): Add them. | ||
| 5 | |||
| 1 | 2012-04-16 Paul Eggert <eggert@cs.ucla.edu> | 6 | 2012-04-16 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 7 | ||
| 3 | Fix minor alloc.c problems found by static checking. | 8 | Fix minor alloc.c problems found by static checking. |
diff --git a/src/dired.c b/src/dired.c index 9b0f94a0760..2c634b9ca6f 100644 --- a/src/dired.c +++ b/src/dired.c | |||
| @@ -1015,6 +1015,45 @@ Comparison is in lexicographic order and case is significant. */) | |||
| 1015 | return Fstring_lessp (Fcar (f1), Fcar (f2)); | 1015 | return Fstring_lessp (Fcar (f1), Fcar (f2)); |
| 1016 | } | 1016 | } |
| 1017 | 1017 | ||
| 1018 | |||
| 1019 | DEFUN ("system-users", Fsystem_users, Ssystem_users, 0, 0, 0, | ||
| 1020 | doc: /* Return a list of user names currently registered in the system. | ||
| 1021 | The value may be nil if not supported on this platform. */) | ||
| 1022 | (void) | ||
| 1023 | { | ||
| 1024 | Lisp_Object users = Qnil; | ||
| 1025 | #if defined(HAVE_GETPWENT) && defined(HAVE_ENDPWENT) | ||
| 1026 | struct passwd *pw; | ||
| 1027 | |||
| 1028 | while ((pw = getpwent ())) | ||
| 1029 | users = Fcons (DECODE_SYSTEM (build_string (pw->pw_name)), users); | ||
| 1030 | |||
| 1031 | endpwent (); | ||
| 1032 | #endif | ||
| 1033 | if (EQ (users, Qnil)) | ||
| 1034 | /* At least current user is always known. */ | ||
| 1035 | users = Fcons (Vuser_real_login_name, Qnil); | ||
| 1036 | return users; | ||
| 1037 | } | ||
| 1038 | |||
| 1039 | DEFUN ("system-groups", Fsystem_groups, Ssystem_groups, 0, 0, 0, | ||
| 1040 | doc: /* Return a list of user group names currently registered in the system. | ||
| 1041 | The value may be nil if not supported on this platform. */) | ||
| 1042 | (void) | ||
| 1043 | { | ||
| 1044 | Lisp_Object groups = Qnil; | ||
| 1045 | #if defined(HAVE_GETGRENT) && defined(HAVE_ENDGRENT) | ||
| 1046 | struct group *gr; | ||
| 1047 | int length; | ||
| 1048 | |||
| 1049 | while ((gr = getgrent ())) | ||
| 1050 | groups = Fcons (DECODE_SYSTEM (build_string (gr->gr_name)), groups); | ||
| 1051 | |||
| 1052 | endgrent (); | ||
| 1053 | #endif | ||
| 1054 | return groups; | ||
| 1055 | } | ||
| 1056 | |||
| 1018 | void | 1057 | void |
| 1019 | syms_of_dired (void) | 1058 | syms_of_dired (void) |
| 1020 | { | 1059 | { |
| @@ -1032,6 +1071,8 @@ syms_of_dired (void) | |||
| 1032 | defsubr (&Sfile_name_all_completions); | 1071 | defsubr (&Sfile_name_all_completions); |
| 1033 | defsubr (&Sfile_attributes); | 1072 | defsubr (&Sfile_attributes); |
| 1034 | defsubr (&Sfile_attributes_lessp); | 1073 | defsubr (&Sfile_attributes_lessp); |
| 1074 | defsubr (&Ssystem_users); | ||
| 1075 | defsubr (&Ssystem_groups); | ||
| 1035 | 1076 | ||
| 1036 | DEFVAR_LISP ("completion-ignored-extensions", Vcompletion_ignored_extensions, | 1077 | DEFVAR_LISP ("completion-ignored-extensions", Vcompletion_ignored_extensions, |
| 1037 | doc: /* Completion ignores file names ending in any string in this list. | 1078 | doc: /* Completion ignores file names ending in any string in this list. |