aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Hansen2003-11-21 18:27:51 +0000
committerLars Hansen2003-11-21 18:27:51 +0000
commit0e6195edf7bff988c9570745f39e7c4ad24d557c (patch)
tree2171f900676ce4786aeab8e39fd870af205cb6a0 /src
parent9ab301de548b428ce2b9fcca637d35aa74005006 (diff)
downloademacs-0e6195edf7bff988c9570745f39e7c4ad24d557c.tar.gz
emacs-0e6195edf7bff988c9570745f39e7c4ad24d557c.zip
(Ffile_attributes): Parameter ID-FORMAT added and included in call to file
name handler. Numeric UID and GID optionally translated to strings. Docstring updated. (directory_files_internal): Parameter ID-FORMAT added. (Fdirectory_files_and_attributes): Parameter ID-FORMAT added and included in call to file name handler and call to directory_files_internal. Docstring updated. (Fdirectory_files): Dummy parameter added in call to directory_files_internal.
Diffstat (limited to 'src')
-rw-r--r--src/dired.c77
1 files changed, 53 insertions, 24 deletions
diff --git a/src/dired.c b/src/dired.c
index 00e5a6587ce..52a19f4fdc6 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -26,6 +26,13 @@ Boston, MA 02111-1307, USA. */
26#include <sys/types.h> 26#include <sys/types.h>
27#include <sys/stat.h> 27#include <sys/stat.h>
28 28
29#ifdef VMS
30#include "vms-pwd.h"
31#else
32#include <pwd.h>
33#include <grp.h>
34#endif
35
29#include "systime.h" 36#include "systime.h"
30#include <errno.h> 37#include <errno.h>
31 38
@@ -132,12 +139,14 @@ directory_files_internal_unwind (dh)
132 139
133/* Function shared by Fdirectory_files and Fdirectory_files_and_attributes. 140/* Function shared by Fdirectory_files and Fdirectory_files_and_attributes.
134 When ATTRS is zero, return a list of directory filenames; when 141 When ATTRS is zero, return a list of directory filenames; when
135 non-zero, return a list of directory filenames and their attributes. */ 142 non-zero, return a list of directory filenames and their attributes.
143 In the latter case, ID_FORMAT is passed to Ffile_attributes. */
136 144
137Lisp_Object 145Lisp_Object
138directory_files_internal (directory, full, match, nosort, attrs) 146directory_files_internal (directory, full, match, nosort, attrs, id_format)
139 Lisp_Object directory, full, match, nosort; 147 Lisp_Object directory, full, match, nosort;
140 int attrs; 148 int attrs;
149 Lisp_Object id_format;
141{ 150{
142 DIR *d; 151 DIR *d;
143 int directory_nbytes; 152 int directory_nbytes;
@@ -295,7 +304,7 @@ directory_files_internal (directory, full, match, nosort, attrs)
295 304
296 /* Both Fexpand_file_name and Ffile_attributes can GC. */ 305 /* Both Fexpand_file_name and Ffile_attributes can GC. */
297 decoded_fullname = Fexpand_file_name (name, directory); 306 decoded_fullname = Fexpand_file_name (name, directory);
298 fileattrs = Ffile_attributes (decoded_fullname); 307 fileattrs = Ffile_attributes (decoded_fullname, id_format);
299 308
300 list = Fcons (Fcons (finalname, fileattrs), list); 309 list = Fcons (Fcons (finalname, fileattrs), list);
301 UNGCPRO; 310 UNGCPRO;
@@ -362,20 +371,22 @@ If NOSORT is non-nil, the list is not sorted--its order is unpredictable.
362 return Ffuncall (6, args); 371 return Ffuncall (6, args);
363 } 372 }
364 373
365 return directory_files_internal (directory, full, match, nosort, 0); 374 return directory_files_internal (directory, full, match, nosort, 0, Qnil);
366} 375}
367 376
368DEFUN ("directory-files-and-attributes", Fdirectory_files_and_attributes, 377DEFUN ("directory-files-and-attributes", Fdirectory_files_and_attributes,
369 Sdirectory_files_and_attributes, 1, 4, 0, 378 Sdirectory_files_and_attributes, 1, 5, 0,
370 doc: /* Return a list of names of files and their attributes in DIRECTORY. 379 doc: /* Return a list of names of files and their attributes in DIRECTORY.
371There are three optional arguments: 380There are four optional arguments:
372If FULL is non-nil, return absolute file names. Otherwise return names 381If FULL is non-nil, return absolute file names. Otherwise return names
373 that are relative to the specified directory. 382 that are relative to the specified directory.
374If MATCH is non-nil, mention only file names that match the regexp MATCH. 383If MATCH is non-nil, mention only file names that match the regexp MATCH.
375If NOSORT is non-nil, the list is not sorted--its order is unpredictable. 384If NOSORT is non-nil, the list is not sorted--its order is unpredictable.
376 NOSORT is useful if you plan to sort the result yourself. */) 385 NOSORT is useful if you plan to sort the result yourself.
377 (directory, full, match, nosort) 386ID-FORMAT specifies the preferred format of attributes uid and gid, see
378 Lisp_Object directory, full, match, nosort; 387`file-attributes' for further documentation. */)
388 (directory, full, match, nosort, id_format)
389 Lisp_Object directory, full, match, nosort, id_format;
379{ 390{
380 Lisp_Object handler; 391 Lisp_Object handler;
381 directory = Fexpand_file_name (directory, Qnil); 392 directory = Fexpand_file_name (directory, Qnil);
@@ -385,7 +396,7 @@ If NOSORT is non-nil, the list is not sorted--its order is unpredictable.
385 handler = Ffind_file_name_handler (directory, Qdirectory_files_and_attributes); 396 handler = Ffind_file_name_handler (directory, Qdirectory_files_and_attributes);
386 if (!NILP (handler)) 397 if (!NILP (handler))
387 { 398 {
388 Lisp_Object args[6]; 399 Lisp_Object args[7];
389 400
390 args[0] = handler; 401 args[0] = handler;
391 args[1] = Qdirectory_files_and_attributes; 402 args[1] = Qdirectory_files_and_attributes;
@@ -393,10 +404,11 @@ If NOSORT is non-nil, the list is not sorted--its order is unpredictable.
393 args[3] = full; 404 args[3] = full;
394 args[4] = match; 405 args[4] = match;
395 args[5] = nosort; 406 args[5] = nosort;
396 return Ffuncall (6, args); 407 args[6] = id_format;
408 return Ffuncall (7, args);
397 } 409 }
398 410
399 return directory_files_internal (directory, full, match, nosort, 1); 411 return directory_files_internal (directory, full, match, nosort, 1, id_format);
400} 412}
401 413
402 414
@@ -872,14 +884,21 @@ make_time (time)
872 Fcons (make_number (time & 0177777), Qnil)); 884 Fcons (make_number (time & 0177777), Qnil));
873} 885}
874 886
875DEFUN ("file-attributes", Ffile_attributes, Sfile_attributes, 1, 1, 0, 887DEFUN ("file-attributes", Ffile_attributes, Sfile_attributes, 1, 2, 0,
876 doc: /* Return a list of attributes of file FILENAME. 888 doc: /* Return a list of attributes of file FILENAME.
877Value is nil if specified file cannot be opened. 889Value is nil if specified file cannot be opened.
878Otherwise, list elements are: 890
891ID-FORMAT specifies the preferred format of attributes uid and gid (see
892below) - valid values are 'string and 'integer. The latter is the default,
893but we plan to change that, so you should specify a non-nil value for
894ID-FORMAT if you use the returned uid or gid.
895
896Elements of the attribute list are:
879 0. t for directory, string (name linked to) for symbolic link, or nil. 897 0. t for directory, string (name linked to) for symbolic link, or nil.
880 1. Number of links to file. 898 1. Number of links to file.
881 2. File uid. 899 2. File uid as a string or an integer. If a string value cannot be
882 3. File gid. 900 looked up, the integer value is returned.
901 3. File gid, likewise.
883 4. Last access time, as a list of two integers. 902 4. Last access time, as a list of two integers.
884 First integer has high-order 16 bits of time, second has low 16 bits. 903 First integer has high-order 16 bits of time, second has low 16 bits.
885 5. Last modification time, likewise. 904 5. Last modification time, likewise.
@@ -892,15 +911,15 @@ Otherwise, list elements are:
892 this is a cons cell containing two integers: first the high part, 911 this is a cons cell containing two integers: first the high part,
893 then the low 16 bits. 912 then the low 16 bits.
89411. Device number. If it is larger than the Emacs integer, this is 91311. Device number. If it is larger than the Emacs integer, this is
895 a cons cell, similar to the inode number. 914 a cons cell, similar to the inode number. */)
896 915 (filename, id_format)
897If file does not exist, returns nil. */) 916 Lisp_Object filename, id_format;
898 (filename)
899 Lisp_Object filename;
900{ 917{
901 Lisp_Object values[12]; 918 Lisp_Object values[12];
902 Lisp_Object encoded; 919 Lisp_Object encoded;
903 struct stat s; 920 struct stat s;
921 struct passwd *pw;
922 struct group *gr;
904#if defined (BSD4_2) || defined (BSD4_3) 923#if defined (BSD4_2) || defined (BSD4_3)
905 Lisp_Object dirname; 924 Lisp_Object dirname;
906 struct stat sdir; 925 struct stat sdir;
@@ -914,7 +933,7 @@ If file does not exist, returns nil. */)
914 call the corresponding file handler. */ 933 call the corresponding file handler. */
915 handler = Ffind_file_name_handler (filename, Qfile_attributes); 934 handler = Ffind_file_name_handler (filename, Qfile_attributes);
916 if (!NILP (handler)) 935 if (!NILP (handler))
917 return call2 (handler, Qfile_attributes, filename); 936 return call3 (handler, Qfile_attributes, filename, id_format);
918 937
919 encoded = ENCODE_FILE (filename); 938 encoded = ENCODE_FILE (filename);
920 939
@@ -933,8 +952,18 @@ If file does not exist, returns nil. */)
933#endif 952#endif
934 } 953 }
935 values[1] = make_number (s.st_nlink); 954 values[1] = make_number (s.st_nlink);
936 values[2] = make_number (s.st_uid); 955 if (NILP (id_format) || EQ (id_format, Qinteger))
937 values[3] = make_number (s.st_gid); 956 {
957 values[2] = make_number (s.st_uid);
958 values[3] = make_number (s.st_gid);
959 }
960 else
961 {
962 pw = (struct passwd *) getpwuid (s.st_uid);
963 values[2] = (pw ? build_string (pw->pw_name) : s.st_uid);
964 gr = (struct group *) getgrgid (s.st_gid);
965 values[3] = (gr ? build_string (gr->gr_name) : s.st_gid);
966 }
938 values[4] = make_time (s.st_atime); 967 values[4] = make_time (s.st_atime);
939 values[5] = make_time (s.st_mtime); 968 values[5] = make_time (s.st_mtime);
940 values[6] = make_time (s.st_ctime); 969 values[6] = make_time (s.st_ctime);