Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /* Reentrant version of rename system call.  */
  2.  
  3. #include <reent.h>
  4. #include <stdio.h>
  5. #include <unistd.h>
  6. #include <sys/stat.h>
  7. #include <_syslist.h>
  8.  
  9. /* Some targets provides their own versions of these functions.  Those
  10.    targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS.  */
  11.  
  12. #ifdef _REENT_ONLY
  13. #ifndef REENTRANT_SYSCALLS_PROVIDED
  14. #define REENTRANT_SYSCALLS_PROVIDED
  15. #endif
  16. #endif
  17.  
  18. #ifndef REENTRANT_SYSCALLS_PROVIDED
  19.  
  20. /* We use the errno variable used by the system dependent layer.  */
  21. #undef errno
  22. extern int errno;
  23.  
  24. /*
  25. FUNCTION
  26.         <<_rename_r>>---Reentrant version of rename
  27.        
  28. INDEX
  29.         _rename_r
  30.  
  31. ANSI_SYNOPSIS
  32.         #include <reent.h>
  33.         int _rename_r(struct _reent *<[ptr]>,
  34.                 const char *<[old]>, const char *<[new]>);
  35.  
  36. TRAD_SYNOPSIS
  37.         #include <reent.h>
  38.         int _rename_r(<[ptr]>, <[old]>, <[new]>)
  39.         struct _reent *<[ptr]>;
  40.         char *<[old]>;
  41.         char *<[new]>;
  42.  
  43. DESCRIPTION
  44.         This is a reentrant version of <<rename>>.  It
  45.         takes a pointer to the global data block, which holds
  46.         <<errno>>.
  47. */
  48.  
  49. int
  50. _DEFUN (_rename_r, (ptr, old, new),
  51.      struct _reent *ptr _AND
  52.      _CONST char *old _AND
  53.      _CONST char *new)
  54. {
  55.   int ret = 0;
  56.  
  57. #ifdef HAVE_RENAME
  58.   errno = 0;
  59.   if ((ret = _rename (old, new)) == -1 && errno != 0)
  60.     ptr->_errno = errno;
  61. #else
  62.   if (_link_r (ptr, old, new) == -1)
  63.     return -1;
  64.  
  65.   if (_unlink_r (ptr, old) == -1)
  66.     {
  67.       /* ??? Should we unlink new? (rhetorical question) */
  68.       return -1;
  69.     }
  70. #endif
  71.   return ret;
  72. }
  73.  
  74. #endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */
  75.