aboutsummaryrefslogtreecommitdiffstats
path: root/src/dired.c
diff options
context:
space:
mode:
authorEli Zaretskii2008-05-09 19:03:52 +0000
committerEli Zaretskii2008-05-09 19:03:52 +0000
commit8aaaec6b622da9620c85862a7cb717d4aee2276f (patch)
tree36df47a50386d7c7843ec718252e5a7aeb28ec52 /src/dired.c
parent71e41ffb85e94bf77260acdb71eed141e6756a6f (diff)
downloademacs-8aaaec6b622da9620c85862a7cb717d4aee2276f.tar.gz
emacs-8aaaec6b622da9620c85862a7cb717d4aee2276f.zip
Support for reporting owner and group of each file on MS-Windows:
* dired.c (stat_uname, stat_gname): New functions, with special implementation for w32. (Ffile_attributes): Use them instead of getpwuid and getgrgid. * w32.c: (g_b_init_get_file_security, g_b_init_get_security_descriptor_owner) (g_b_init_get_security_descriptor_group, g_b_init_is_valid_sid): New initialization states. (globals_of_w32): Initialize them to zero. Initialize the default group name to "None". (GetFileSecurity_Name): New global var, the name of the function to call for GetFileSecurity. (GetFileSecurity_Proc, GetSecurityDescriptorOwner_Proc) (GetSecurityDescriptorGroup_Proc, IsValidSid_Proc): New typedefs. (get_file_security, get_security_descriptor_owner) (get_security_descriptor_group, is_valid_sid) (get_file_security_desc, get_rid, get_name_and_id) (get_file_owner_and_group): New functions. (stat): Use get_file_security_desc and get_file_owner_and_group to report the owner and primary group of each file. Don't ignore the high 32 bits of file's size, now that st_size is 64-bit wide. Fix test when to get true file attributes. (init_user_info): Use get_rid instead of equivalent inline code. (fstat): Don't ignore the high 32 bits of file's size.
Diffstat (limited to 'src/dired.c')
-rw-r--r--src/dired.c45
1 files changed, 37 insertions, 8 deletions
diff --git a/src/dired.c b/src/dired.c
index d3a6e7b7cec..7b4c9166545 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -899,6 +899,36 @@ make_time (time)
899 Fcons (make_number (time & 0177777), Qnil)); 899 Fcons (make_number (time & 0177777), Qnil));
900} 900}
901 901
902static char *
903stat_uname (struct stat *st)
904{
905#ifdef WINDOWSNT
906 return st->st_uname;
907#else
908 struct passwd *pw = (struct passwd *) getpwuid (st->st_uid);
909
910 if (pw)
911 return pw->pw_name;
912 else
913 return NULL;
914#endif
915}
916
917static char *
918stat_gname (struct stat *st)
919{
920#ifdef WINDOWSNT
921 return st->st_gname;
922#else
923 struct group *gr = (struct group *) getgrgid (st->st_gid);
924
925 if (gr)
926 return gr->gr_name;
927 else
928 return NULL;
929#endif
930}
931
902DEFUN ("file-attributes", Ffile_attributes, Sfile_attributes, 1, 2, 0, 932DEFUN ("file-attributes", Ffile_attributes, Sfile_attributes, 1, 2, 0,
903 doc: /* Return a list of attributes of file FILENAME. 933 doc: /* Return a list of attributes of file FILENAME.
904Value is nil if specified file cannot be opened. 934Value is nil if specified file cannot be opened.
@@ -935,8 +965,6 @@ Elements of the attribute list are:
935 Lisp_Object values[12]; 965 Lisp_Object values[12];
936 Lisp_Object encoded; 966 Lisp_Object encoded;
937 struct stat s; 967 struct stat s;
938 struct passwd *pw;
939 struct group *gr;
940#if defined (BSD4_2) || defined (BSD4_3) 968#if defined (BSD4_2) || defined (BSD4_3)
941 Lisp_Object dirname; 969 Lisp_Object dirname;
942 struct stat sdir; 970 struct stat sdir;
@@ -945,6 +973,7 @@ Elements of the attribute list are:
945 Lisp_Object handler; 973 Lisp_Object handler;
946 struct gcpro gcpro1; 974 struct gcpro gcpro1;
947 EMACS_INT ino; 975 EMACS_INT ino;
976 char *uname, *gname;
948 977
949 filename = Fexpand_file_name (filename, Qnil); 978 filename = Fexpand_file_name (filename, Qnil);
950 979
@@ -987,12 +1016,12 @@ Elements of the attribute list are:
987 else 1016 else
988 { 1017 {
989 BLOCK_INPUT; 1018 BLOCK_INPUT;
990 pw = (struct passwd *) getpwuid (s.st_uid); 1019 uname = stat_uname (&s);
991 values[2] = (pw ? build_string (pw->pw_name) 1020 values[2] = (uname ? build_string (uname)
992 : make_fixnum_or_float (s.st_uid)); 1021 : make_fixnum_or_float (s.st_uid));
993 gr = (struct group *) getgrgid (s.st_gid); 1022 gname = stat_gname (&s);
994 values[3] = (gr ? build_string (gr->gr_name) 1023 values[3] = (gname ? build_string (gname)
995 : make_fixnum_or_float (s.st_gid)); 1024 : make_fixnum_or_float (s.st_gid));
996 UNBLOCK_INPUT; 1025 UNBLOCK_INPUT;
997 } 1026 }
998 values[4] = make_time (s.st_atime); 1027 values[4] = make_time (s.st_atime);