aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2009-03-20 17:58:10 +0000
committerEli Zaretskii2009-03-20 17:58:10 +0000
commit51105b132455a6a37633a782823d4c10eae7e0cb (patch)
treeee2d28b05df1bc8ee2e7934b3fecff73a39fe4c3 /src
parent2bc9f1df7d93fba9d2e62c0d35a428edd71bb248 (diff)
downloademacs-51105b132455a6a37633a782823d4c10eae7e0cb.tar.gz
emacs-51105b132455a6a37633a782823d4c10eae7e0cb.zip
(make_uid, make_gid): New functions.
(Ffile_attributes): Use them to avoid negative UID and GID.
Diffstat (limited to 'src')
-rw-r--r--src/dired.c56
1 files changed, 35 insertions, 21 deletions
diff --git a/src/dired.c b/src/dired.c
index 7c7c7571a4a..3505448017e 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -894,6 +894,29 @@ stat_gname (struct stat *st)
894#endif 894#endif
895} 895}
896 896
897/* Make an integer or float number for UID and GID, while being
898 careful not to produce negative numbers due to signed integer
899 overflow. */
900static Lisp_Object
901make_uid (struct stat *st)
902{
903 EMACS_INT uid = st->st_uid;
904
905 if (sizeof (st->st_uid) > sizeof (uid) || uid < 0 || FIXNUM_OVERFLOW_P (uid))
906 return make_float ((double)st->st_uid);
907 return make_number (uid);
908}
909
910static Lisp_Object
911make_gid (struct stat *st)
912{
913 EMACS_INT gid = st->st_gid;
914
915 if (sizeof (st->st_gid) > sizeof (gid) || gid < 0 || FIXNUM_OVERFLOW_P (gid))
916 return make_float ((double)st->st_gid);
917 return make_number (gid);
918}
919
897DEFUN ("file-attributes", Ffile_attributes, Sfile_attributes, 1, 2, 0, 920DEFUN ("file-attributes", Ffile_attributes, Sfile_attributes, 1, 2, 0,
898 doc: /* Return a list of attributes of file FILENAME. 921 doc: /* Return a list of attributes of file FILENAME.
899Value is nil if specified file cannot be opened. 922Value is nil if specified file cannot be opened.
@@ -941,7 +964,7 @@ which see. */)
941 Lisp_Object handler; 964 Lisp_Object handler;
942 struct gcpro gcpro1; 965 struct gcpro gcpro1;
943 EMACS_INT ino, uid, gid; 966 EMACS_INT ino, uid, gid;
944 char *uname, *gname; 967 char *uname = NULL, *gname = NULL;
945 968
946 filename = Fexpand_file_name (filename, Qnil); 969 filename = Fexpand_file_name (filename, Qnil);
947 970
@@ -976,32 +999,23 @@ which see. */)
976#endif 999#endif
977 } 1000 }
978 values[1] = make_number (s.st_nlink); 1001 values[1] = make_number (s.st_nlink);
979 uid = s.st_uid; 1002
980 gid = s.st_gid; 1003 if (!(NILP (id_format) || EQ (id_format, Qinteger)))
981 if (NILP (id_format) || EQ (id_format, Qinteger))
982 {
983 if (sizeof (s.st_uid) > sizeof (uid) || uid < 0
984 || FIXNUM_OVERFLOW_P (uid))
985 values[2] = make_float ((double)s.st_uid);
986 else
987 values[2] = make_number (uid);
988 if (sizeof (s.st_gid) > sizeof (gid) || gid < 0
989 || FIXNUM_OVERFLOW_P (gid))
990 values[3] = make_float ((double)s.st_gid);
991 else
992 values[3] = make_number (gid);
993 }
994 else
995 { 1004 {
996 BLOCK_INPUT; 1005 BLOCK_INPUT;
997 uname = stat_uname (&s); 1006 uname = stat_uname (&s);
998 values[2] = (uname ? build_string (uname)
999 : make_fixnum_or_float (uid));
1000 gname = stat_gname (&s); 1007 gname = stat_gname (&s);
1001 values[3] = (gname ? build_string (gname)
1002 : make_fixnum_or_float (gid));
1003 UNBLOCK_INPUT; 1008 UNBLOCK_INPUT;
1004 } 1009 }
1010 if (uname)
1011 values[2] = build_string (uname);
1012 else
1013 values[2] = make_uid (&s);
1014 if (gname)
1015 values[3] = build_string (gname);
1016 else
1017 values[3] = make_gid (&s);
1018
1005 values[4] = make_time (s.st_atime); 1019 values[4] = make_time (s.st_atime);
1006 values[5] = make_time (s.st_mtime); 1020 values[5] = make_time (s.st_mtime);
1007 values[6] = make_time (s.st_ctime); 1021 values[6] = make_time (s.st_ctime);