]> pd.if.org Git - pdclib/blob - platform/example/functions/_PDCLIB/rename.c
Porting current working set from CVS.
[pdclib] / platform / example / functions / _PDCLIB / rename.c
1 /* $Id$ */
2
3 /* Release $Name$ */
4
5 /* _PDCLIB_rename( const char *, const char * )
6
7    This file is part of the Public Domain C Library (PDCLib).
8    Permission is granted to use, modify, and / or redistribute at will.
9 */
10
11 #ifndef REGTEST
12 #include <unistd.h>
13 #include <_PDCLIB_glue.h>
14
15 int _PDCLIB_rename( const char * old, const char * new )
16 {
17     /* Note that the behaviour if new file exists is implementation-defined.
18        There is nothing wrong with either overwriting it or failing the
19        operation, but you might want to document whichever you chose.
20        This example fails if new file exists.
21     */
22     if ( link( old, new ) == 0 )
23     {
24         return unlink( old );
25     }
26     else
27     {
28         return -1;
29     }
30 }
31
32 #endif
33
34 #ifdef TEST
35 #include <_PDCLIB_test.h>
36
37 int main( void )
38 {
39     TESTCASE( NO_TESTDRIVER );
40     return TEST_RESULTS;
41 }
42
43 #endif