Mercurial > hg > xemacs-beta
comparison src/dired.c @ 5733:c30fdcab7bc8
Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
src/ChangeLog:
2013-04-19 Mats Lidell <matsl@xemacs.org>
* sysdep.c (qxe_getgrgid): Encapsulation of getgrgid.
* syspwd.h: Ditto.
* dired.c (Ffile_attributes): Added optional ID-FORMAT for
compatibility with GNU.
author | Mats Lidell <mats.lidell@cag.se> |
---|---|
date | Sat, 20 Apr 2013 00:04:58 +0200 |
parents | 86d33ddc7fd6 |
children | ff13c44ce0d9 |
comparison
equal
deleted
inserted
replaced
5732:02d0124c6314 | 5733:c30fdcab7bc8 |
---|---|
1 /* Lisp functions for making directory listings. | 1 /* Lisp functions for making directory listings. |
2 Copyright (C) 1985, 1986, 1992, 1993, 1994 Free Software Foundation, Inc. | 2 Copyright (C) 1985, 1986, 1992, 1993, 1994, 2013 Free Software Foundation, Inc. |
3 Copyright (C) 2001, 2002 Ben Wing. | 3 Copyright (C) 2001, 2002 Ben Wing. |
4 | 4 |
5 This file is part of XEmacs. | 5 This file is part of XEmacs. |
6 | 6 |
7 XEmacs is free software: you can redistribute it and/or modify it | 7 XEmacs is free software: you can redistribute it and/or modify it |
818 XCDR (cons) = Fcons (XCDR (cons), Qnil); | 818 XCDR (cons) = Fcons (XCDR (cons), Qnil); |
819 return cons; | 819 return cons; |
820 } | 820 } |
821 #endif | 821 #endif |
822 | 822 |
823 DEFUN ("file-attributes", Ffile_attributes, 1, 1, 0, /* | 823 DEFUN ("file-attributes", Ffile_attributes, 1, 2, 0, /* |
824 Return a list of attributes of file FILENAME. | 824 Return a list of attributes of file FILENAME. |
825 Value is nil if specified file cannot be opened. | 825 Value is nil if specified file cannot be opened. |
826 | |
827 ID-FORMAT specifies the preferred format of attributes uid and gid (see | |
828 below) - valid values are 'string and 'integer. The latter is the | |
829 default. | |
830 | |
826 Otherwise, list elements are: | 831 Otherwise, list elements are: |
827 0. t for directory, string (name linked to) for symbolic link, or nil. | 832 0. t for directory, string (name linked to) for symbolic link, or nil. |
828 1. Number of links to file. | 833 1. Number of links to file. |
829 2. File uid. | 834 2. File uid as a string or a number. If a string value cannot be |
830 3. File gid. | 835 looked up, a numeric value, either an integer or a float, is returned. |
836 3. File gid, likewise. | |
831 4. Last access time, as a list of two integers. | 837 4. Last access time, as a list of two integers. |
832 First integer has high-order 16 bits of time, second has low 16 bits. | 838 First integer has high-order 16 bits of time, second has low 16 bits. |
833 5. Last modification time, likewise. | 839 5. Last modification time, likewise. |
834 6. Last status change time, likewise. | 840 6. Last status change time, likewise. |
835 7. Size in bytes. (-1, if number out of range and no bignum support.) | 841 7. Size in bytes. (-1, if number out of range and no bignum support.) |
838 10. inode number. | 844 10. inode number. |
839 11. Device number. | 845 11. Device number. |
840 | 846 |
841 If file does not exist, returns nil. | 847 If file does not exist, returns nil. |
842 */ | 848 */ |
843 (filename)) | 849 (filename, id_format)) |
844 { | 850 { |
845 /* This function can GC. GC checked 1997.06.04. */ | 851 /* This function can GC. GC checked 1997.06.04. */ |
846 Lisp_Object directory = Qnil; | 852 Lisp_Object directory = Qnil; |
847 struct stat s; | 853 struct stat s; |
848 char modes[10]; | 854 char modes[10]; |
849 Lisp_Object handler, mode, modestring = Qnil, size, gid; | 855 Lisp_Object handler, mode, modestring = Qnil, size, gid; |
850 struct gcpro gcpro1, gcpro2, gcpro3; | 856 struct gcpro gcpro1, gcpro2, gcpro3; |
851 | 857 |
858 Lisp_Object uidInfo = Qnil; | |
859 Lisp_Object gidInfo = Qnil; | |
860 | |
852 GCPRO3 (filename, directory, modestring); | 861 GCPRO3 (filename, directory, modestring); |
853 filename = Fexpand_file_name (filename, Qnil); | 862 filename = Fexpand_file_name (filename, Qnil); |
854 | 863 |
855 /* If the file name has special constructs in it, | 864 /* If the file name has special constructs in it, |
856 call the corresponding file handler. */ | 865 call the corresponding file handler. */ |
857 handler = Ffind_file_name_handler (filename, Qfile_attributes); | 866 handler = Ffind_file_name_handler (filename, Qfile_attributes); |
858 if (!NILP (handler)) | 867 if (!NILP (handler)) |
859 { | 868 { |
860 UNGCPRO; | 869 UNGCPRO; |
861 return call2 (handler, Qfile_attributes, filename); | 870 if (NILP(id_format)) |
871 return call2 (handler, Qfile_attributes, filename); | |
872 else | |
873 return call3 (handler, Qfile_attributes, filename, id_format); | |
862 } | 874 } |
863 | 875 |
864 if (qxe_lstat (XSTRING_DATA (filename), &s) < 0) | 876 if (qxe_lstat (XSTRING_DATA (filename), &s) < 0) |
865 { | 877 { |
866 UNGCPRO; | 878 UNGCPRO; |
923 } | 935 } |
924 #else /* file gid will be egid */ | 936 #else /* file gid will be egid */ |
925 gid = (s.st_gid != getegid ()) ? Qt : Qnil; | 937 gid = (s.st_gid != getegid ()) ? Qt : Qnil; |
926 #endif /* BSD4_2 or BSD4_3 */ | 938 #endif /* BSD4_2 or BSD4_3 */ |
927 | 939 |
940 if (NILP(id_format) || EQ (id_format, Qinteger)) | |
941 { | |
942 uidInfo = make_integer (s.st_uid); | |
943 gidInfo = make_integer (s.st_gid); | |
944 } | |
945 else | |
946 { | |
947 struct passwd *pw = qxe_getpwuid (s.st_uid); | |
948 struct group *gr = qxe_getgrgid (s.st_gid); | |
949 | |
950 uidInfo = build_istring (pw ? (Ibyte *) pw->pw_name : NULL); | |
951 gidInfo = build_istring (gr ? (Ibyte *) gr->gr_name : NULL); | |
952 } | |
953 | |
928 RETURN_UNGCPRO (listn (12, | 954 RETURN_UNGCPRO (listn (12, |
929 mode, | 955 mode, |
930 make_integer (s.st_nlink), | 956 make_integer (s.st_nlink), |
931 make_integer (s.st_uid), | 957 uidInfo, |
932 make_integer (s.st_gid), | 958 gidInfo, |
933 make_time (s.st_atime), | 959 make_time (s.st_atime), |
934 make_time (s.st_mtime), | 960 make_time (s.st_mtime), |
935 make_time (s.st_ctime), | 961 make_time (s.st_ctime), |
936 size, | 962 size, |
937 modestring, | 963 modestring, |