]> code.delx.au - gnu-emacs/blobdiff - src/fileio.c
More xmalloc and related cleanup.
[gnu-emacs] / src / fileio.c
index 6c3a3b206e8966cf63fb8d9ceb50bf2af76f995c..0f6a1d5f79951b2de29abda9e9012ba0337e5864 100644 (file)
@@ -336,7 +336,7 @@ Given a Unix syntax file name, returns a string ending in slash.  */)
 
   filename = FILE_SYSTEM_CASE (filename);
 #ifdef DOS_NT
-  beg = (char *) alloca (SBYTES (filename) + 1);
+  beg = alloca (SBYTES (filename) + 1);
   memcpy (beg, SSDATA (filename), SBYTES (filename) + 1);
 #else
   beg = SSDATA (filename);
@@ -510,7 +510,7 @@ For a Unix-syntax file name, just appends a slash.  */)
       error ("Invalid handler in `file-name-handler-alist'");
     }
 
-  buf = (char *) alloca (SBYTES (file) + 10);
+  buf = alloca (SBYTES (file) + 10);
   file_name_as_directory (buf, SSDATA (file));
   return make_specified_string (buf, -1, strlen (buf),
                                STRING_MULTIBYTE (file));
@@ -575,7 +575,7 @@ In Unix-syntax, this function just removes the final slash.  */)
       error ("Invalid handler in `file-name-handler-alist'");
     }
 
-  buf = (char *) alloca (SBYTES (directory) + 20);
+  buf = alloca (SBYTES (directory) + 20);
   directory_file_name (SSDATA (directory), buf);
   return make_specified_string (buf, -1, strlen (buf),
                                STRING_MULTIBYTE (directory));
@@ -878,7 +878,7 @@ filesystem tree, not (expand-file-name ".."  dirname).  */)
     }
 
   /* Make a local copy of nm[] to protect it from GC in DECODE_FILE below.  */
-  nm = (char *) alloca (SBYTES (name) + 1);
+  nm = alloca (SBYTES (name) + 1);
   memcpy (nm, SSDATA (name), SBYTES (name) + 1);
 
 #ifdef DOS_NT
@@ -1186,7 +1186,7 @@ filesystem tree, not (expand-file-name ".."  dirname).  */)
 #endif
          )
        {
-         char *temp = (char *) alloca (length);
+         char *temp = alloca (length);
          memcpy (temp, newdir, length - 1);
          temp[length - 1] = 0;
          newdir = temp;
@@ -1202,10 +1202,10 @@ filesystem tree, not (expand-file-name ".."  dirname).  */)
   /* Reserve space for drive specifier and escape prefix, since either
      or both may need to be inserted.  (The Microsoft x86 compiler
      produces incorrect code if the following two lines are combined.)  */
-  target = (char *) alloca (tlen + 4);
+  target = alloca (tlen + 4);
   target += 4;
 #else  /* not DOS_NT */
-  target = (char *) alloca (tlen);
+  target = alloca (tlen);
 #endif /* not DOS_NT */
   *target = 0;
 
@@ -1415,7 +1415,7 @@ See also the function `substitute-in-file-name'.")
        unsigned char *ptr = (unsigned char *) strchr (user, '/');
        ptrdiff_t len = ptr ? ptr - user : strlen (user);
        /* Copy the user name into temp storage.  */
-       o = (unsigned char *) alloca (len + 1);
+       o = alloca (len + 1);
        memcpy (o, user, len);
        o[len] = 0;
 
@@ -1443,7 +1443,7 @@ See also the function `substitute-in-file-name'.")
   /* Now concatenate the directory and name to new space in the stack frame.  */
 
   tlen = (newdir ? strlen (newdir) + 1 : 0) + strlen (nm) + 1;
-  target = (unsigned char *) alloca (tlen);
+  target = alloca (tlen);
   *target = 0;
 
   if (newdir)
@@ -1593,7 +1593,7 @@ those `/' is discarded.  */)
   /* Always work on a copy of the string, in case GC happens during
      decode of environment variables, causing the original Lisp_String
      data to be relocated.  */
-  nm = (char *) alloca (SBYTES (filename) + 1);
+  nm = alloca (SBYTES (filename) + 1);
   memcpy (nm, SDATA (filename), SBYTES (filename) + 1);
 
 #ifdef DOS_NT
@@ -1645,7 +1645,7 @@ those `/' is discarded.  */)
          }
 
        /* Copy out the variable name.  */
-       target = (char *) alloca (s - o + 1);
+       target = alloca (s - o + 1);
        strncpy (target, o, s - o);
        target[s - o] = 0;
 #ifdef DOS_NT
@@ -1676,7 +1676,7 @@ those `/' is discarded.  */)
 
   /* If substitution required, recopy the string and do it.  */
   /* Make space in stack frame for the new copy.  */
-  xnm = (char *) alloca (SBYTES (filename) + total + 1);
+  xnm = alloca (SBYTES (filename) + total + 1);
   x = xnm;
 
   /* Copy the rest of the name through, replacing $ constructs with values.  */
@@ -1708,7 +1708,7 @@ those `/' is discarded.  */)
          }
 
        /* Copy out the variable name.  */
-       target = (char *) alloca (s - o + 1);
+       target = alloca (s - o + 1);
        strncpy (target, o, s - o);
        target[s - o] = 0;
 #ifdef DOS_NT
@@ -3079,8 +3079,7 @@ otherwise, if FILE2 does not exist, the answer is t.  */)
   (Lisp_Object file1, Lisp_Object file2)
 {
   Lisp_Object absname1, absname2;
-  struct stat st;
-  int mtime1;
+  struct stat st1, st2;
   Lisp_Object handler;
   struct gcpro gcpro1, gcpro2;
 
@@ -3106,15 +3105,14 @@ otherwise, if FILE2 does not exist, the answer is t.  */)
   absname2 = ENCODE_FILE (absname2);
   UNGCPRO;
 
-  if (stat (SSDATA (absname1), &st) < 0)
+  if (stat (SSDATA (absname1), &st1) < 0)
     return Qnil;
 
-  mtime1 = st.st_mtime;
-
-  if (stat (SSDATA (absname2), &st) < 0)
+  if (stat (SSDATA (absname2), &st2) < 0)
     return Qt;
 
-  return (mtime1 > st.st_mtime) ? Qt : Qnil;
+  return (EMACS_TIME_GT (get_stat_mtime (&st1), get_stat_mtime (&st2))
+         ? Qt : Qnil);
 }
 \f
 #ifndef READ_BUF_SIZE
@@ -3215,12 +3213,12 @@ emacs_lseek (int fd, EMACS_INT offset, int whence)
   return lseek (fd, offset, whence);
 }
 
-/* Return a special mtime value indicating the error number ERRNUM.  */
+/* Return a special time value indicating the error number ERRNUM.  */
 static EMACS_TIME
-special_mtime (int errnum)
+time_error_value (int errnum)
 {
   EMACS_TIME t;
-  int ns = (errno == ENOENT || errno == EACCES || errno == ENOTDIR
+  int ns = (errnum == ENOENT || errnum == EACCES || errnum == ENOTDIR
            ? NONEXISTENT_MODTIME_NSECS
            : UNKNOWN_MODTIME_NSECS);
   EMACS_SET_SECS_NSECS (t, 0, ns);
@@ -3338,7 +3336,7 @@ variable `last-coding-system-used' to the coding system actually used.  */)
       save_errno = errno;
       if (NILP (visit))
        report_file_error ("Opening input file", Fcons (orig_filename, Qnil));
-      mtime = special_mtime (save_errno);
+      mtime = time_error_value (save_errno);
       st.st_size = -1;
       how_much = 0;
       if (!NILP (Vcoding_system_for_read))
@@ -5108,7 +5106,7 @@ See Info node `(elisp)Modification Time' for more details.  */)
 
   mtime = (stat (SSDATA (filename), &st) == 0
           ? get_stat_mtime (&st)
-          : special_mtime (errno));
+          : time_error_value (errno));
   if ((EMACS_TIME_EQ (mtime, b->modtime)
        /* If both exist, accept them if they are off by one second.  */
        || (EMACS_TIME_VALID_P (mtime) && EMACS_TIME_VALID_P (b->modtime)