X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=platform%2Fexample%2Ffunctions%2F_PDCLIB%2Frename.c;fp=platform%2Fexample%2Ffunctions%2F_PDCLIB%2Frename.c;h=9996e7c73bf0882dc15c904aeb9b5dc1b32e1593;hb=d02f38605b53cdff5460cc6b9e1b2a80c3a2ba4c;hp=0000000000000000000000000000000000000000;hpb=3f6094115e79a45413f08361b68b71eb08da306e;p=pdclib diff --git a/platform/example/functions/_PDCLIB/rename.c b/platform/example/functions/_PDCLIB/rename.c new file mode 100644 index 0000000..9996e7c --- /dev/null +++ b/platform/example/functions/_PDCLIB/rename.c @@ -0,0 +1,43 @@ +/* $Id$ */ + +/* Release $Name$ */ + +/* _PDCLIB_rename( const char *, const char * ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#ifndef REGTEST +#include +#include <_PDCLIB_glue.h> + +int _PDCLIB_rename( const char * old, const char * new ) +{ + /* Note that the behaviour if new file exists is implementation-defined. + There is nothing wrong with either overwriting it or failing the + operation, but you might want to document whichever you chose. + This example fails if new file exists. + */ + if ( link( old, new ) == 0 ) + { + return unlink( old ); + } + else + { + return -1; + } +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + TESTCASE( NO_TESTDRIVER ); + return TEST_RESULTS; +} + +#endif