]> pd.if.org Git - pdclib/blobdiff - platform/example/functions/_PDCLIB/remove.c
Porting current working set from CVS.
[pdclib] / platform / example / functions / _PDCLIB / remove.c
diff --git a/platform/example/functions/_PDCLIB/remove.c b/platform/example/functions/_PDCLIB/remove.c
new file mode 100644 (file)
index 0000000..403fcda
--- /dev/null
@@ -0,0 +1,46 @@
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* _PDCLIB_remove( const char * )
+
+   This file is part of the Public Domain C Library (PDCLib).
+   Permission is granted to use, modify, and / or redistribute at will.
+*/
+
+/* This is an example implementation of _PDCLIB_remove() (declared in
+   _PDCLIB_glue.h), fit for use in POSIX kernels.
+   NOTE: Linux is *not* POSIX-compliant in this, as it sets EISDIR instead of
+   EPERM if you try to unlink a directory. Check the manpage for unlink(2).
+*/
+
+#ifndef REGTEST
+#include <_PDCLIB_glue.h>
+#include <errno.h>
+#include <unistd.h>
+
+int _PDCLIB_remove( const char * filename )
+{
+    int prev_errno = errno;
+    int rc;
+    errno = 0;
+    if ( ( ( rc = unlink( filename ) ) != 0 ) && ( errno == EPERM ) )
+    {
+        rc = rmdir( filename );
+    }
+    errno = prev_errno;
+    return rc;
+}
+
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main( void )
+{
+    TESTCASE( NO_TESTDRIVER );
+    return TEST_RESULTS;
+}
+
+#endif