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