XEmacs 21.2.24 "Hecate".
[chise/xemacs-chise.git.1] / src / fileio.c
index 0f21f16..015cd00 100644 (file)
@@ -71,7 +71,7 @@ Boston, MA 02111-1307, USA.  */
 /* Need to lower-case the drive letter, or else expanded
    filenames will sometimes compare inequal, because
    `expand-file-name' doesn't always down-case the drive letter.  */
-#define DRIVE_LETTER(x) (tolower (x))
+#define DRIVE_LETTER(x) tolower (x)
 #endif /* WINDOWSNT */
 
 int lisp_to_time (Lisp_Object, time_t *);
@@ -109,8 +109,6 @@ Lisp_Object Vauto_save_list_file_name;
 
 int disable_auto_save_when_buffer_shrinks;
 
-Lisp_Object Qfile_name_handler_alist;
-
 Lisp_Object Vdirectory_sep_char;
 
 /* These variables describe handlers that have "already" had a chance
@@ -282,18 +280,16 @@ restore_point_unwind (Lisp_Object point_marker)
    signal handler) because that's way too losing.
 
    (#### Actually, longjmp()ing out of the signal handler may not be
-   as losing as I thought.  See sys_do_signal() in sysdep.c.)
+   as losing as I thought.  See sys_do_signal() in sysdep.c.) */
 
-   Solaris include files declare the return value as ssize_t.
-   Is that standard? */
-int
+ssize_t
 read_allowing_quit (int fildes, void *buf, size_t size)
 {
   QUIT;
   return sys_read_1 (fildes, buf, size, 1);
 }
 
-int
+ssize_t
 write_allowing_quit (int fildes, CONST void *buf, size_t size)
 {
   QUIT;
@@ -438,7 +434,7 @@ Given a Unix syntax file name, returns a string ending in slash.
 
   while (p != beg && !IS_ANY_SEP (p[-1])
 #ifdef WINDOWSNT
-        /* only recognise drive specifier at beginning */
+        /* only recognize drive specifier at beginning */
         && !(p[-1] == ':' && p == beg + 2)
 #endif
     ) p--;
@@ -454,13 +450,16 @@ Given a Unix syntax file name, returns a string ending in slash.
       Bufbyte *res = alloca (MAXPATHLEN + 1);
       if (getdefdir (toupper (*beg) - 'A' + 1, res))
        {
-         if (!IS_DIRECTORY_SEP (res[strlen ((char *) res) - 1]))
-           strcat ((char *) res, "/");
+         char *c=((char *) res) + strlen ((char *) res);
+         if (!IS_DIRECTORY_SEP (*c))
+           {
+             *c++ = DIRECTORY_SEP;
+             *c = '\0';
+           }
          beg = res;
          p = beg + strlen ((char *) beg);
        }
     }
-  CORRECT_DIR_SEPS (beg);
 #endif /* WINDOWSNT */
   return make_string (beg, p - beg);
 }
@@ -490,7 +489,7 @@ or the entire name if it contains no slash.
 
   while (p != beg && !IS_ANY_SEP (p[-1])
 #ifdef WINDOWSNT
-        /* only recognise drive specifier at beginning */
+        /* only recognize drive specifier at beginning */
         && !(p[-1] == ':' && p == beg + 2)
 #endif
     ) p--;
@@ -544,9 +543,6 @@ file_name_as_directory (char *out, char *in)
          out[size + 1] = '\0';
        }
     }
-#ifdef WINDOWSNT
-  CORRECT_DIR_SEPS (out);
-#endif
   return out;
 }
 
@@ -608,9 +604,6 @@ directory_file_name (CONST char *src, char *dst)
       )
     dst[slen - 1] = 0;
 #endif /* APOLLO */
-#ifdef WINDOWSNT
-  CORRECT_DIR_SEPS (dst);
-#endif /* WINDOWSNT */
   return 1;
 }
 
@@ -745,18 +738,17 @@ be an absolute file name.
          /* We want to return only if errno is ENOENT.  */
          if (errno == ENOENT)
            return val;
-         else
-           /* The error here is dubious, but there is little else we
-              can do.  The alternatives are to return nil, which is
-              as bad as (and in many cases worse than) throwing the
-              error, or to ignore the error, which will likely result
-              in inflooping.  */
-           report_file_error ("Cannot create temporary name for prefix",
-                              list1 (prefix));
-         /* not reached */
+
+         /* The error here is dubious, but there is little else we
+            can do.  The alternatives are to return nil, which is
+            as bad as (and in many cases worse than) throwing the
+            error, or to ignore the error, which will likely result
+            in inflooping.  */
+         report_file_error ("Cannot create temporary name for prefix",
+                            list1 (prefix));
+         return Qnil; /* not reached */
        }
     }
-  RETURN_NOT_REACHED (Qnil);
 }
 
 \f
@@ -872,7 +864,7 @@ See also the function `substitute-in-file-name'.
 
     if (colon)
       /* Only recognize colon as part of drive specifier if there is a
-        single alphabetic character preceeding the colon (and if the
+        single alphabetic character preceding the colon (and if the
         character before the drive letter, if present, is a directory
         separator); this is to support the remote system syntax used by
         ange-ftp, and the "po:username" syntax for POP mailboxes. */
@@ -985,8 +977,13 @@ See also the function `substitute-in-file-name'.
       if (IS_DIRECTORY_SEP (nm[1])
          || nm[1] == 0)        /* ~ by itself */
        {
-         if (!(newdir = (Bufbyte *) get_home_directory()))
+         char * newdir_external = get_home_directory ();
+
+         if (newdir_external == NULL)
            newdir = (Bufbyte *) "";
+         else
+           GET_C_CHARPTR_INT_FILENAME_DATA_ALLOCA (newdir_external, newdir);
+
          nm++;
 #ifdef WINDOWSNT
          collapse_newdir = 0;
@@ -994,7 +991,8 @@ See also the function `substitute-in-file-name'.
        }
       else                     /* ~user/filename */
        {
-         for (p = nm; *p && (!IS_DIRECTORY_SEP (*p)); p++);
+         for (p = nm; *p && (!IS_DIRECTORY_SEP (*p)); p++)
+           DO_NOTHING;
          o = (Bufbyte *) alloca (p - nm + 1);
          memcpy (o, (char *) nm, p - nm);
          o [p - nm] = 0;
@@ -1020,14 +1018,14 @@ See also the function `substitute-in-file-name'.
          if ((user = user_login_name (NULL)) != NULL)
            {
              /* Does the user login name match the ~name? */
-             if (strcmp(user,((char *) o + 1)) == 0)
-               { 
-                 newdir = (Bufbyte *)  get_home_directory();
+             if (strcmp (user, (char *) o + 1) == 0)
+               {
+                 newdir = (Bufbyte *) get_home_directory();
                  nm = p;
                }
            }
           if (! newdir)
-            {  
+            {
 #endif /* __CYGWIN32__ */
          /* Jamie reports that getpwnam() can get wedged by SIGIO/SIGALARM
             occurring in it. (It can call select()). */
@@ -1258,8 +1256,7 @@ See also the function `substitute-in-file-name'.
     }
   else
     {
-      if (!(IS_DIRECTORY_SEP (target[0]) && IS_DIRECTORY_SEP (target[1])))
-      abort ();
+      assert (IS_DIRECTORY_SEP (target[0]) && IS_DIRECTORY_SEP (target[1]));
     }
   CORRECT_DIR_SEPS (target);
 #endif /* WINDOWSNT */
@@ -1302,19 +1299,19 @@ No component of the resulting pathname will be a symbolic link, as
 
   {
     char resolved_path[MAXPATHLEN];
-    char path[MAXPATHLEN];
-    char *p = path;
-    int elen = XSTRING_LENGTH (expanded_name);
+    Extbyte *path;
+    Extbyte *p;
+    Extcount elen = XSTRING_LENGTH (expanded_name);
 
-    if (elen >= countof (path))
+    GET_STRING_FILENAME_DATA_ALLOCA (expanded_name,path,elen);
+    p = path;
+    if (elen > MAXPATHLEN)
       goto toolong;
-
-    memcpy (path, XSTRING_DATA (expanded_name), elen + 1);
-    /* memset (resolved_path, 0, sizeof (resolved_path)); */
-
+    
     /* Try doing it all at once. */
-    /* !!#### Does realpath() Mule-encapsulate? */
-    if (!xrealpath (path, resolved_path))
+    /* !! Does realpath() Mule-encapsulate?
+       Answer: Nope! So we do it above */
+    if (!xrealpath ((char *) path, resolved_path))
       {
        /* Didn't resolve it -- have to do it one component at a time. */
        /* "realpath" is a typically useless, stupid un*x piece of crap.
@@ -1324,12 +1321,12 @@ No component of the resulting pathname will be a symbolic link, as
           partial result returned.  What a piece of junk. */
        for (;;)
          {
-           p = (char *) memchr (p + 1, '/', elen - (p + 1 - path));
+           p = (Extbyte *) memchr (p + 1, '/', elen - (p + 1 - path));
            if (p)
              *p = 0;
 
            /* memset (resolved_path, 0, sizeof (resolved_path)); */
-           if (xrealpath (path, resolved_path))
+           if (xrealpath ((char *) path, resolved_path))
              {
                if (p)
                  *p = '/';
@@ -1773,7 +1770,7 @@ A prefix arg makes KEEP-TIME non-nil.
     }
 #endif /* S_ISREG && S_ISLNK */
 
-  ofd = open( (char *) XSTRING_DATA (newname), 
+  ofd = open( (char *) XSTRING_DATA (newname),
              O_WRONLY | O_CREAT | O_TRUNC | OPEN_BINARY, CREAT_MODE);
   if (ofd < 0)
     report_file_error ("Opening output file", list1 (newname));
@@ -1997,7 +1994,7 @@ This is what happens in interactive use with M-x.
          Fcopy_file (filename, newname,
                      /* We have already prompted if it was an integer,
                         so don't have copy-file prompt again.  */
-                     ((NILP (ok_if_already_exists)) ? Qnil : Qt),
+                     (NILP (ok_if_already_exists) ? Qnil : Qt),
                       Qt);
          Fdelete_file (filename);
        }
@@ -2052,7 +2049,7 @@ This is what happens in interactive use with M-x.
    on NT here. --marcpa */
 /* But FSF #defines link as sys_link which is supplied in nt.c. We can't do
    that because sysfile.h defines sys_link depending on ENCAPSULATE_LINK.
-   Reverted to previous behaviour pending a working fix. (jhar) */
+   Reverted to previous behavior pending a working fix. (jhar) */
 #if defined(WINDOWSNT)
   /* Windows does not support this operation.  */
   report_file_error ("Adding new name", Flist (2, &filename));
@@ -2288,7 +2285,7 @@ See also `file-exists-p' and `file-attributes'.
   if (!NILP (handler))
     RETURN_UNGCPRO (call2 (handler, Qfile_readable_p, abspath));
 
-#ifdef WINDOWSNT
+#if defined(WINDOWSNT) || defined(__CYGWIN32__)
   /* Under MS-DOS and Windows, open does not work for directories.  */
   UNGCPRO;
   if (access (XSTRING_DATA (abspath), 0) == 0)
@@ -2528,7 +2525,7 @@ Return mode bits of FILE, as an integer.
   /* Syncing with FSF 19.34.6 note: not in FSF, #if 0'ed out here. */
 #if 0
 #ifdef DOS_NT
-  if (check_executable (XSTRING (abspath)->_data))
+  if (check_executable (XSTRING_DATA (abspath)))
     st.st_mode |= S_IEXEC;
 #endif /* DOS_NT */
 #endif /* 0 */
@@ -2983,7 +2980,7 @@ positions), even in Mule. (Fixing this is very difficult.)
        occurs inside of the filedesc stream. */
     while (1)
       {
-       Bytecount this_len;
+       ssize_t this_len;
        Charcount cc_inserted;
 
        QUIT;
@@ -3349,7 +3346,10 @@ to the value of CODESYS.  If this is nil, no code conversion occurs.
     /* On VMS and APOLLO, must do the stat after the close
        since closing changes the modtime.  */
     /* As it does on Windows too - kkm */
-#if !defined (WINDOWSNT) /* !defined (VMS) && !defined (APOLLO) */
+    /* The spurious warnings appear on Linux too.  Rather than handling
+       this on a per-system basis, unconditionally do the stat after the close - cgw */
+
+#if 0 /* !defined (WINDOWSNT) */  /* !defined (VMS) && !defined (APOLLO) */
     fstat (desc, &st);
 #endif
 
@@ -3367,9 +3367,9 @@ to the value of CODESYS.  If this is nil, no code conversion occurs.
     unbind_to (speccount, Qnil);
   }
 
-#if defined (WINDOWSNT) /* defined (VMS) || defined (APOLLO) */
+  /* # if defined (WINDOWSNT) */ /* defined (VMS) || defined (APOLLO) */
   stat ((char *) XSTRING_DATA (fn), &st);
-#endif
+  /* #endif */
 
 #ifdef CLASH_DETECTION
   if (!auto_saving)
@@ -3429,7 +3429,10 @@ Return t if (car A) is numerically less than (car B).
 */
        (a, b))
 {
-  return arithcompare (Fcar (a), Fcar (b), arith_less);
+  Lisp_Object objs[2];
+  objs[0] = Fcar (a);
+  objs[1] = Fcar (b);
+  return Flss (2, objs);
 }
 
 /* Heh heh heh, let's define this too, just to aggravate the person who
@@ -3439,7 +3442,10 @@ Return t if (cdr A) is numerically less than (cdr B).
 */
        (a, b))
 {
-  return arithcompare (Fcdr (a), Fcdr (b), arith_less);
+  Lisp_Object objs[2];
+  objs[0] = Fcdr (a);
+  objs[1] = Fcdr (b);
+  return Flss (2, objs);
 }
 
 /* Build the complete list of annotations appropriate for writing out
@@ -3828,7 +3834,7 @@ auto_save_expand_name (Lisp_Object name)
   struct gcpro gcpro1;
 
   /* note that caller did NOT gc protect name, so we do it. */
-  /* #### dmoore - this might not be neccessary, if condition_case_1
+  /* #### dmoore - this might not be necessary, if condition_case_1
      protects it.  but I don't think it does. */
   GCPRO1 (name);
   RETURN_UNGCPRO (Fexpand_file_name (name, Qnil));
@@ -3899,7 +3905,7 @@ Non-nil second argument means save only current buffer.
 
   run_hook (Qauto_save_hook);
 
-  if (GC_STRINGP (Vauto_save_list_file_name))
+  if (STRINGP (Vauto_save_list_file_name))
     listfile = condition_case_1 (Qt,
                                 auto_save_expand_name,
                                 Vauto_save_list_file_name,
@@ -3918,13 +3924,13 @@ Non-nil second argument means save only current buffer.
   for (do_handled_files = 0; do_handled_files < 2; do_handled_files++)
     {
       for (tail = Vbuffer_alist;
-          GC_CONSP (tail);
+          CONSP (tail);
           tail = XCDR (tail))
        {
          buf = XCDR (XCAR (tail));
          b = XBUFFER (buf);
 
-         if (!GC_NILP (current_only)
+         if (!NILP (current_only)
              && b != current_buffer)
            continue;
 
@@ -3936,7 +3942,7 @@ Non-nil second argument means save only current buffer.
          /* Check for auto save enabled
             and file changed since last auto save
             and file changed since last real save.  */
-         if (GC_STRINGP (b->auto_save_file_name)
+         if (STRINGP (b->auto_save_file_name)
              && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b)
              && b->auto_save_modified < BUF_MODIFF (b)
              /* -1 means we've turned off autosaving for a while--see below.  */
@@ -3981,7 +3987,7 @@ Non-nil second argument means save only current buffer.
                  continue;
                }
              set_buffer_internal (b);
-             if (!auto_saved && GC_NILP (no_message))
+             if (!auto_saved && NILP (no_message))
                {
                  static CONST unsigned char *msg
                    = (CONST unsigned char *) "Auto-saving...";
@@ -3993,7 +3999,7 @@ Non-nil second argument means save only current buffer.
              /* Open the auto-save list file, if necessary.
                 We only do this now so that the file only exists
                 if we actually auto-saved any files. */
-             if (!auto_saved && GC_STRINGP (listfile) && listdesc < 0)
+             if (!auto_saved && STRINGP (listfile) && listdesc < 0)
                {
                  listdesc = open ((char *) XSTRING_DATA (listfile),
                                   O_WRONLY | O_TRUNC | O_CREAT | OPEN_BINARY,
@@ -4082,7 +4088,7 @@ Non-nil second argument means save only current buffer.
      one because nothing needed to be auto-saved.  Do this afterwards
      rather than before in case we get a crash attempting to autosave
      (in that case we'd still want the old one around). */
-  if (listdesc < 0 && !auto_saved && GC_STRINGP (listfile))
+  if (listdesc < 0 && !auto_saved && STRINGP (listfile))
     unlink ((char *) XSTRING_DATA (listfile));
 
   /* Show "...done" only if the echo area would otherwise be empty. */
@@ -4170,7 +4176,6 @@ syms_of_fileio (void)
   defsymbol (&Qset_visited_file_modtime, "set-visited-file-modtime");
   defsymbol (&Qcar_less_than_car, "car-less-than-car"); /* Vomitous! */
 
-  defsymbol (&Qfile_name_handler_alist, "file-name-handler-alist");
   defsymbol (&Qauto_save_hook, "auto-save-hook");
   defsymbol (&Qauto_save_error, "auto-save-error");
   defsymbol (&Qauto_saving, "auto-saving");
@@ -4328,5 +4333,9 @@ This variable affects the built-in functions only on Windows,
 on other platforms, it is initialized so that Lisp code can find out
 what the normal separator is.
 */ );
-  Vdirectory_sep_char = make_char ('/');
+#ifdef WINDOWSNT
+  Vdirectory_sep_char = make_char ('\\');
+#else
+   Vdirectory_sep_char = make_char ('/');
+#endif
 }