[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rename, delete and move current buffer and file

From: Clément Pit-Claudel
Subject: Re: Rename, delete and move current buffer and file
Date: Fri, 11 May 2018 12:06:17 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

On 2018-05-11 11:45, Paul Eggert wrote:
> On 05/11/2018 08:33 AM, Stefan Monnier wrote:
>>> That method has been obsolete for decades.  POSIX requires rename
>>> to be atomic.
>> Even when moving from one directory to another?
> Yes, that requirement has been in POSIX ever since POSIX was
> introduced; I just now checked my printed copy of IEEE Std
> 1003.1-1988.
I don't know much about this, so sorry if the following is silly. Hopefully 
someone can clarify.  The glibc implementation of rename in 
glibc/sysdeps/posix/rename.c is this:

    /* Rename the file OLD to NEW.  */
    rename (const char *old, const char *new)
      int save = errno;
      if (__link (old, new) < 0)
          if (errno == EEXIST)
          __set_errno (save);
          /* Race condition, required for 1003.1 conformance.  */
          if (__unlink (new) < 0 ||
              __link (old, new) < 0)
            return -1;
        return -1;
      if (__unlink (old) < 0)
          save = errno;
          if (__unlink (new) == 0)
        __set_errno (save);
          return -1;
      return 0;

Is this just a fallback implementation (the "obsolete for decades" method that 
Andreas referred to?), unused on most platforms?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]