rename()

Stefan Bellon sbellon at sbellon.de
Fri Aug 13 02:02:01 PDT 2004


Nick Burrett wrote:
> Stefan Bellon said:

> > On RISC OS, rename(a, b) fails if b already exists. On GNU/Linux,
> > rename(a, b) just overwrites b if it already exists.
> >
> > Is there any way to make rename() on RISC OS behave the same. And
> > moreover, is it possible to make it an atomar operation, i.e. not
> > just doing unlink(b); rename(a, b)?
> >
> > It's all about race conditions of concurrent processes.

> Both of these are possible.  I would be interested to know how the
> SCL's rename function performs here.  Does it fail or does it
> overwrite 'b' ?

It fails. The StrongHelp manual says that it simply calls
OS_FSControl,25 which fails if the target object exists.

The comment in clib's stdio.h reads as follows:

  [rename] causes the file whose name is the string pointed to by old
  to be henceforth known by the name given by the string pointed to by
  new. The file named old is effectively removed. If a file named by
  the string pointed to by new exists prior to the call of the rename
  function, the behaviour is implementation-defined (under
  RISCOS/Arthur/Brazil, the operation fails).
  Returns: zero if the operation succeeds, nonzero if it fails, in which
           case if the file existed previously it is still known by its
           original name.

I'd be interested in how you think you can make rename() behave like
e.g. the Single Unix Specification says. How can this be done in an
atomar operation on RISC OS?

-- 
Stefan Bellon



More information about the gcc mailing list