]> pd.if.org Git - pdclib/blobdiff - platform/example/functions/_PDCLIB/rename.c
Porting current working set from CVS.
[pdclib] / platform / example / functions / _PDCLIB / rename.c
diff --git a/platform/example/functions/_PDCLIB/rename.c b/platform/example/functions/_PDCLIB/rename.c
new file mode 100644 (file)
index 0000000..9996e7c
--- /dev/null
@@ -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 <unistd.h>
+#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