]> code.delx.au - gnu-emacs/blobdiff - src/fileio.c
Delete the code that was trying to define BSD "right"
[gnu-emacs] / src / fileio.c
index 65219833360dcd1894b375d9128444fc2b8b3318..9caa355dac5316b8338ee124720c80da5b8960bc 100644 (file)
@@ -1251,7 +1251,7 @@ See also the function `substitute-in-file-name'.")
       /* Get rid of any slash at the end of newdir, unless newdir is
        just // (an incomplete UNC name). */
       length = strlen (newdir);
-      if (IS_DIRECTORY_SEP (newdir[length - 1])
+      if (length > 0 && IS_DIRECTORY_SEP (newdir[length - 1])
 #ifdef WINDOWSNT
          && !(length == 2 && IS_DIRECTORY_SEP (newdir[0]))
 #endif
@@ -1379,7 +1379,8 @@ See also the function `substitute-in-file-name'.")
        {
          while (o != target && (--o) && !IS_DIRECTORY_SEP (*o))
            ;
-         if (o == target && IS_ANY_SEP (*o))
+         /* Keep initial / only if this is the whole name.  */
+         if (o == target && IS_ANY_SEP (*o) && p[3] == 0)
            ++o;
          p += 3;
        }
@@ -1921,7 +1922,7 @@ duplicates what `expand-file-name' does.")
         || IS_DIRECTORY_SEP (p[0])
 #endif /* not (APOLLO || WINDOWSNT) */
         )
-       && p != nm && IS_DIRECTORY_SEP (p[-1]))
+       && p != xnm && IS_DIRECTORY_SEP (p[-1]))
       xnm = p;
 #ifdef DOS_NT
     else if (IS_DRIVE (p[0]) && p[1] == ':'
@@ -2130,7 +2131,7 @@ A prefix arg makes KEEP-TIME non-nil.")
          EMACS_SET_SECS_USECS (mtime, st.st_mtime, 0);
          if (set_file_times (XSTRING (newname)->data, atime, mtime))
            Fsignal (Qfile_date_error,
-                    Fcons (build_string ("File already exists"),
+                    Fcons (build_string ("Cannot set file date"),
                            Fcons (newname, Qnil)));
        }
 #ifndef MSDOS
@@ -3101,13 +3102,15 @@ This does code conversion according to the value of\n\
      least signal an error.  */
   if (!S_ISREG (st.st_mode))
     {
-      if (NILP (visit))
+      not_regular = 1;
+
+      if (! NILP (visit))
+       goto notfound;
+
+      if (! NILP (replace) || ! NILP (beg) || ! NILP (end))
        Fsignal (Qfile_error,
                 Fcons (build_string ("not a regular file"),
                        Fcons (filename, Qnil)));
-
-      not_regular = 1;
-      goto notfound;
     }
 #endif
 
@@ -3122,7 +3125,7 @@ This does code conversion according to the value of\n\
   record_unwind_protect (close_file_unwind, make_number (fd));
 
   /* Supposedly happens on VMS.  */
-  if (st.st_size < 0)
+  if (! not_regular && st.st_size < 0)
     error ("File size is negative");
 
   if (!NILP (beg) || !NILP (end))
@@ -3138,9 +3141,12 @@ This does code conversion according to the value of\n\
     CHECK_NUMBER (end, 0);
   else
     {
-      XSETINT (end, st.st_size);
-      if (XINT (end) != st.st_size)
-       error ("maximum buffer size exceeded");
+      if (! not_regular)
+       {
+         XSETINT (end, st.st_size);
+         if (XINT (end) != st.st_size)
+           error ("Maximum buffer size exceeded");
+       }
     }
 
   /* If requested, replace the accessible part of the buffer
@@ -3463,7 +3469,8 @@ This does code conversion according to the value of\n\
       inserted -= (Z - same_at_end) + (same_at_start - BEG);
       move_gap (same_at_start);
       del_range_1 (same_at_start, same_at_end, 0);
-      insert (conversion_buffer + same_at_start - BEG, inserted);
+      SET_PT (same_at_start);
+      insert_1 (conversion_buffer + same_at_start - BEG, inserted, 0, 0);
 
       free (conversion_buffer);
       close (fd);
@@ -3472,16 +3479,20 @@ This does code conversion according to the value of\n\
       goto handled;
     }
 
-  total = XINT (end) - XINT (beg);
+  if (! not_regular)
+    {
+      register Lisp_Object temp;
 
-  {
-    register Lisp_Object temp;
+      total = XINT (end) - XINT (beg);
 
-    /* Make sure point-max won't overflow after this insertion.  */
-    XSETINT (temp, total);
-    if (total != XINT (temp))
-      error ("maximum buffer size exceeded");
-  }
+      /* Make sure point-max won't overflow after this insertion.  */
+      XSETINT (temp, total);
+      if (total != XINT (temp))
+       error ("Maximum buffer size exceeded");
+    }
+  else
+    /* For a special file, all we can do is guess.  */
+    total = READ_BUF_SIZE;
 
   if (NILP (visit) && total > 0)
     prepare_to_modify_buffer (PT, PT);
@@ -3525,7 +3536,13 @@ This does code conversion according to the value of\n\
          break;
        }
 
-      how_much += this;
+      /* For a regular file, where TOTAL is the real size,
+        count HOW_MUCH to compare with it.
+        For a special file, where TOTAL is just a buffer size,
+        so don't bother counting in HOW_MUCH.
+        (INSERTED is where we count the number of characters inserted.)  */
+      if (! not_regular)
+       how_much += this;
 
       if (CODING_REQUIRE_CONVERSION (&coding))
        {
@@ -3536,8 +3553,21 @@ This does code conversion according to the value of\n\
          require = decoding_buffer_size (&coding, this);
          if (GAP_SIZE < require)
            make_gap (require - GAP_SIZE);
-         if (how_much >= total)  /* This is the last block.  */
-           coding.last_block = 1;
+
+         if (! not_regular)
+           {
+             if (how_much >= total)  /* This is the last block.  */
+               coding.last_block = 1;
+           }
+         else
+           {
+             /* If we encounter EOF, say it is the last block.  (The
+                data this will apply to is the UNPROCESSED characters
+                carried over from the last batch.)  */
+             if (this == 0)
+               coding.last_block = 1;
+           }
+
          produced = decode_coding (&coding, read_buf,
                                    POS_ADDR (PT + inserted - 1) + 1,
                                    this, GAP_SIZE, &consumed);
@@ -3659,7 +3689,11 @@ This does code conversion according to the value of\n\
       inserted = XFASTINT (insval);
     }
 
-  if (inserted > 0 && NILP (visit) && total > 0)
+  /* Call after-change hooks for the inserted text, aside from the case
+     of normal visiting (not with REPLACE), which is done in a new buffer
+     "before" the buffer is changed.  */
+  if (inserted > 0 && total > 0
+      && (NILP (visit) || !NILP (replace)))
     signal_after_change (PT, 0, inserted);
 
   if (inserted > 0)
@@ -3766,7 +3800,7 @@ This does code conversion according to the value of\n\
   if (!NILP (start) && !STRINGP (start))
     validate_region (&start, &end);
 
-  GCPRO3 (filename, visit, lockname);
+  GCPRO4 (start, filename, visit, lockname);
   filename = Fexpand_file_name (filename, Qnil);
   if (STRINGP (visit))
     visit_file = Fexpand_file_name (visit, Qnil);
@@ -4820,7 +4854,7 @@ DIR defaults to current buffer's directory default.")
   GCPRO2 (insdef, default_filename);
   val = Fcompleting_read (prompt, intern ("read-file-name-internal"),
                          dir, mustmatch, insdef1,
-                         Qfile_name_history);
+                         Qfile_name_history, default_filename);
 
 #ifdef VMS
   unbind_to (count, Qnil);