OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libc/] [stdio/] [rename.c] - Blame information for rev 1773

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1010 ivang
/*
2
FUNCTION
3
<<rename>>---rename a file
4
 
5
INDEX
6
        rename
7
INDEX
8
        _rename_r
9
 
10
ANSI_SYNOPSIS
11
        #include <stdio.h>
12
        int rename(const char *<[old]>, const char *<[new]>);
13
 
14
        int _rename_r(void *<[reent]>,
15
                      const char *<[old]>, const char *<[new]>);
16
 
17
TRAD_SYNOPSIS
18
        #include <stdio.h>
19
        int rename(<[old]>, <[new]>)
20
        char *<[old]>;
21
        char *<[new]>;
22
 
23
        int _rename_r(<[reent]>, <[old]>, <[new]>)
24
        char *<[reent]>;
25
        char *<[old]>;
26
        char *<[new]>;
27
 
28
DESCRIPTION
29
Use <<rename>> to establish a new name (the string at <[new]>) for a
30
file now known by the string at <[old]>.  After a successful
31
<<rename>>, the file is no longer accessible by the string at <[old]>.
32
 
33
If <<rename>> fails, the file named <<*<[old]>>> is unaffected.  The
34
conditions for failure depend on the host operating system.
35
 
36
The alternate function <<_rename_r>> is a reentrant version.  The
37
extra argument <[reent]> is a pointer to a reentrancy structure.
38
 
39
RETURNS
40
The result is either <<0>> (when successful) or <<-1>> (when the file
41
could not be renamed).
42
 
43
PORTABILITY
44
ANSI C requires <<rename>>, but only specifies that the result on
45
failure be nonzero.  The effects of using the name of an existing file
46
as <<*<[new]>>> may vary from one implementation to another.
47
 
48
Supporting OS subroutines required: <<link>>, <<unlink>>, or <<rename>>.
49
*/
50
 
51
#include <stdio.h>
52
#include <sys/unistd.h>
53
#include <reent.h>
54
 
55
int
56
_rename_r (ptr, old, new)
57
     struct _reent *ptr;
58
     _CONST char *old;
59
     _CONST char *new;
60
{
61
#ifdef HAVE_RENAME
62
  return _rename (old,new);
63
#else
64
  if (_link_r (ptr, old, new) == -1)
65
    return -1;
66
 
67
  if (_unlink_r (ptr, old) == -1)
68
    {
69
      /* ??? Should we unlink new? (rhetorical question) */
70
      return -1;
71
    }
72
#endif
73
  return 0;
74
}
75
 
76
#ifndef _REENT_ONLY
77
 
78
int
79
rename (old, new)
80
     _CONST char *old;
81
     _CONST char *new;
82
{
83
  return _rename_r (_REENT, old, new);
84
}
85
 
86
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.