aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndreas Schwab2009-10-24 16:34:52 +0000
committerAndreas Schwab2009-10-24 16:34:52 +0000
commit58a128895203804c027b61cefe32c32e16904b57 (patch)
tree72e9c4e22c91fb59a495e1cee7207de20a896f39 /src
parent987c93276e7a43944cdaef61f7b2aa8fbf7f4d87 (diff)
downloademacs-58a128895203804c027b61cefe32c32e16904b57.tar.gz
emacs-58a128895203804c027b61cefe32c32e16904b57.zip
(Ffile_attributes): Simplify now that FIXNUM_OVERFLOW_P
can properly handle unsigned types. (make_uid, make_gid): Removed.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog4
-rw-r--r--src/dired.c53
2 files changed, 12 insertions, 45 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 8ff2ec0fa80..1a2d994bad6 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,9 @@
12009-10-24 Andreas Schwab <schwab@linux-m68k.org> 12009-10-24 Andreas Schwab <schwab@linux-m68k.org>
2 2
3 * dired.c (Ffile_attributes): Simplify now that FIXNUM_OVERFLOW_P
4 can properly handle unsigned types.
5 (make_uid, make_gid): Removed.
6
3 * lisp.h (FIXNUM_OVERFLOW_P): Fix last change to handle unsigned 7 * lisp.h (FIXNUM_OVERFLOW_P): Fix last change to handle unsigned
4 types again. 8 types again.
5 9
diff --git a/src/dired.c b/src/dired.c
index 67002d32eb7..5aedd045870 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -934,29 +934,6 @@ stat_gname (struct stat *st)
934#endif 934#endif
935} 935}
936 936
937/* Make an integer or float number for UID and GID, while being
938 careful not to produce negative numbers due to signed integer
939 overflow. */
940static Lisp_Object
941make_uid (struct stat *st)
942{
943 EMACS_INT uid = st->st_uid;
944
945 if (sizeof (st->st_uid) > sizeof (uid) || uid < 0 || FIXNUM_OVERFLOW_P (uid))
946 return make_float ((double)st->st_uid);
947 return make_number (uid);
948}
949
950static Lisp_Object
951make_gid (struct stat *st)
952{
953 EMACS_INT gid = st->st_gid;
954
955 if (sizeof (st->st_gid) > sizeof (gid) || gid < 0 || FIXNUM_OVERFLOW_P (gid))
956 return make_float ((double)st->st_gid);
957 return make_number (gid);
958}
959
960DEFUN ("file-attributes", Ffile_attributes, Sfile_attributes, 1, 2, 0, 937DEFUN ("file-attributes", Ffile_attributes, Sfile_attributes, 1, 2, 0,
961 doc: /* Return a list of attributes of file FILENAME. 938 doc: /* Return a list of attributes of file FILENAME.
962Value is nil if specified file cannot be opened. 939Value is nil if specified file cannot be opened.
@@ -1013,7 +990,6 @@ so last access time will always be midnight of that day. */)
1013 char modes[10]; 990 char modes[10];
1014 Lisp_Object handler; 991 Lisp_Object handler;
1015 struct gcpro gcpro1; 992 struct gcpro gcpro1;
1016 EMACS_INT ino, uid, gid;
1017 char *uname = NULL, *gname = NULL; 993 char *uname = NULL, *gname = NULL;
1018 994
1019 filename = Fexpand_file_name (filename, Qnil); 995 filename = Fexpand_file_name (filename, Qnil);
@@ -1060,19 +1036,16 @@ so last access time will always be midnight of that day. */)
1060 if (uname) 1036 if (uname)
1061 values[2] = DECODE_SYSTEM (build_string (uname)); 1037 values[2] = DECODE_SYSTEM (build_string (uname));
1062 else 1038 else
1063 values[2] = make_uid (&s); 1039 values[2] = make_fixnum_or_float (s.st_uid);
1064 if (gname) 1040 if (gname)
1065 values[3] = DECODE_SYSTEM (build_string (gname)); 1041 values[3] = DECODE_SYSTEM (build_string (gname));
1066 else 1042 else
1067 values[3] = make_gid (&s); 1043 values[3] = make_fixnum_or_float (s.st_gid);
1068 1044
1069 values[4] = make_time (s.st_atime); 1045 values[4] = make_time (s.st_atime);
1070 values[5] = make_time (s.st_mtime); 1046 values[5] = make_time (s.st_mtime);
1071 values[6] = make_time (s.st_ctime); 1047 values[6] = make_time (s.st_ctime);
1072 values[7] = make_number (s.st_size); 1048 values[7] = make_fixnum_or_float (s.st_size);
1073 /* If the size is out of range for an integer, return a float. */
1074 if (XINT (values[7]) != s.st_size)
1075 values[7] = make_float ((double)s.st_size);
1076 /* If the size is negative, and its type is long, convert it back to 1049 /* If the size is negative, and its type is long, convert it back to
1077 positive. */ 1050 positive. */
1078 if (s.st_size < 0 && sizeof (s.st_size) == sizeof (long)) 1051 if (s.st_size < 0 && sizeof (s.st_size) == sizeof (long))
@@ -1091,17 +1064,10 @@ so last access time will always be midnight of that day. */)
1091#else /* file gid will be egid */ 1064#else /* file gid will be egid */
1092 values[9] = (s.st_gid != getegid ()) ? Qt : Qnil; 1065 values[9] = (s.st_gid != getegid ()) ? Qt : Qnil;
1093#endif /* BSD4_2 (or BSD4_3) */ 1066#endif /* BSD4_2 (or BSD4_3) */
1094 /* Shut up GCC warnings in FIXNUM_OVERFLOW_P below. */ 1067 if (!FIXNUM_OVERFLOW_P (s.st_ino))
1095 if (sizeof (s.st_ino) > sizeof (ino))
1096 ino = (EMACS_INT)(s.st_ino & 0xffffffff);
1097 else
1098 ino = s.st_ino;
1099 if (!FIXNUM_OVERFLOW_P (ino)
1100 && (sizeof (s.st_ino) <= sizeof (ino) || (s.st_ino & ~INTMASK) == 0))
1101 /* Keep the most common cases as integers. */ 1068 /* Keep the most common cases as integers. */
1102 values[10] = make_number (ino); 1069 values[10] = make_number (s.st_ino);
1103 else if (sizeof (s.st_ino) <= sizeof (ino) 1070 else if (!FIXNUM_OVERFLOW_P (s.st_ino >> 16))
1104 || ((s.st_ino >> 16) & ~INTMASK) == 0)
1105 /* To allow inode numbers larger than VALBITS, separate the bottom 1071 /* To allow inode numbers larger than VALBITS, separate the bottom
1106 16 bits. */ 1072 16 bits. */
1107 values[10] = Fcons (make_number ((EMACS_INT)(s.st_ino >> 16)), 1073 values[10] = Fcons (make_number ((EMACS_INT)(s.st_ino >> 16)),
@@ -1121,11 +1087,8 @@ so last access time will always be midnight of that day. */)
1121 make_number (low_ino & 0xffff))); 1087 make_number (low_ino & 0xffff)));
1122 } 1088 }
1123 1089
1124 /* Likewise for device, but don't let it become negative. We used 1090 /* Likewise for device. */
1125 to use FIXNUM_OVERFLOW_P here, but that won't catch large 1091 if (FIXNUM_OVERFLOW_P (s.st_dev))
1126 positive numbers such as 0xFFEEDDCC. */
1127 if ((EMACS_INT)s.st_dev < 0
1128 || (EMACS_INT)s.st_dev > MOST_POSITIVE_FIXNUM)
1129 values[11] = Fcons (make_number (s.st_dev >> 16), 1092 values[11] = Fcons (make_number (s.st_dev >> 16),
1130 make_number (s.st_dev & 0xffff)); 1093 make_number (s.st_dev & 0xffff));
1131 else 1094 else