X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=platform%2Fexample%2Ffunctions%2F_PDCLIB%2Fremove.c;fp=platform%2Fexample%2Ffunctions%2F_PDCLIB%2Fremove.c;h=403fcda875ec7cb83c889b2438e292a5e88389ba;hb=12e17136786afb1775c9dc946cbe41f5e230c24a;hp=0000000000000000000000000000000000000000;hpb=9489b93733c00be5a94e2ee5b349457c78184a1a;p=pdclib.old diff --git a/platform/example/functions/_PDCLIB/remove.c b/platform/example/functions/_PDCLIB/remove.c new file mode 100644 index 0000000..403fcda --- /dev/null +++ b/platform/example/functions/_PDCLIB/remove.c @@ -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 +#include + +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