3 /* rename( const char *, const char * )
5 This file is part of the Public Domain C Library (PDCLib).
6 Permission is granted to use, modify, and / or redistribute at will.
12 #include <_PDCLIB_glue.h>
14 int rename( const char * old, const char * new )
16 /* TODO: Search open file list, flush and close file */
17 return _PDCLIB_rename( old, new );
23 /* TODO: Work around the following undef */
25 #include <_PDCLIB_test.h>
31 /* TODO: Extend to internal testing (buffer etc.) */
32 char filename1[] = "touch testfile1";
33 char filename2[] = "testfile2";
34 /* check that neither file exists */
35 TESTCASE( fopen( filename1 + 6, "r" ) == NULL );
36 TESTCASE( fopen( filename2, "r" ) == NULL );
37 /* rename file 1 to file 2 - expected to fail */
38 TESTCASE( rename( filename1 + 6, filename2 ) == -1 );
41 /* check that file 1 exists */
42 TESTCASE( fopen( filename1 + 6, "r" ) != NULL );
43 /* rename file 1 to file 2 */
44 TESTCASE( rename( filename1 + 6, filename2 ) == 0 );
45 /* check that file 2 exists, file 1 does not */
46 TESTCASE( fopen( filename1 + 6, "r" ) == NULL );
47 TESTCASE( fopen( filename2, "r" ) != NULL );
48 /* create another file 1 */
50 /* check that file 1 exists */
51 TESTCASE( fopen( filename1 + 6, "r" ) != NULL );
52 /* rename file 1 to file 2 - expected to fail, see comment in
53 _PDCLIB_rename() itself.
56 TESTCASE( rename( filename1 + 6, filename2 ) == -1 );
58 /* glibc rename() overwrites existing destination file. */
59 TESTCASE( rename( filename1 + 6, filename2 ) == 0 );
61 /* remove both files */
62 remove( filename1 + 6 );
64 /* check that they're gone */
65 TESTCASE( fopen( filename1 + 6, "r" ) == NULL );
66 TESTCASE( fopen( filename2, "r" ) == NULL );