Richard Stallman <[EMAIL PROTECTED]> writes:

>     Or could one check the C code for "insert-file-contents"?  Does it
>     mark the buffer modified if 0 bytes were read.
>
> The code appears specifically to avoid marking the buffer modified
> if the file has zero size.  I just did a test, inserting an empty
> file into a buffer this way.  It did not mark the buffer modified
> and did not lock the file.
>
> Something we don't understand must be happening, and only you
> are in a position to debug it.

I have spent some time tracing the code of insert-file-contents.  I do
not understand what it is trying to do, to be honest, but this is what
it **appears** to be doing:  If the file it is trying to read has ZERO
bytes according to what stat() returns, it does the following:

----lines 176-181 of fileio.c
          /* The file size returned from stat may be zero, but data
             may be readable nonetheless, for example when this is a
             file in the /proc filesystem.  */
          if (st.st_size == 0)
            XSETINT (end, READ_BUF_SIZE);
---------

This has the effect of setting the amount to be read to non-zero.
Around line 707 it does

      total = XINT (end) - XINT (beg);

setting total to something very much other than zero (some buffer
size), and in the next if statement (line 718)

  if (NILP (visit) && total > 0)
    prepare_to_modify_buffer (PT, PT, NULL);

which as far as I can tell calls lock_file on the underlying file.
Any other suggestions/ideas?  

--Boris

PS. I can see the comment in fileio.c regarding /proc and can guess
that this sometimes might come in handy, but I do not see why reading
a regular zero-byte file should force a modification and/or locking of
the current buffer.  But if I am right, I do not see how reading a
zero-byte file can EVER work right.  Richard said he tried some casual
tests and it seems to work.  I just tried creating a file qqqq in /tmp,
visiting it, and doing (insert-file-contents "/var/mail/whatever") and
lo and behold, a lock file for /tmp/qqqq showed up!  Just tried it
again with /tmp/empty in place of /var/mail/whatever---same effect.
Does it mean that 0-size insertion is just broken on my machine
(Solaris 5.7, gcc 3.1)?



_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

Reply via email to