X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=platform%2Fexample%2Ffunctions%2F_PDCLIB%2Fremove.c;h=609ddbe4b49d70b3a722e29fe6838fb8b73c1cb5;hb=ddc340b8ebc7da1b3e5083dc2a8542f4a13683f3;hp=403fcda875ec7cb83c889b2438e292a5e88389ba;hpb=d02f38605b53cdff5460cc6b9e1b2a80c3a2ba4c;p=pdclib diff --git a/platform/example/functions/_PDCLIB/remove.c b/platform/example/functions/_PDCLIB/remove.c index 403fcda..609ddbe 100644 --- a/platform/example/functions/_PDCLIB/remove.c +++ b/platform/example/functions/_PDCLIB/remove.c @@ -1,7 +1,5 @@ /* $Id$ */ -/* Release $Name$ */ - /* _PDCLIB_remove( const char * ) This file is part of the Public Domain C Library (PDCLib). @@ -24,7 +22,7 @@ int _PDCLIB_remove( const char * filename ) int prev_errno = errno; int rc; errno = 0; - if ( ( ( rc = unlink( filename ) ) != 0 ) && ( errno == EPERM ) ) + if ( ( ( rc = unlink( filename ) ) != 0 ) && ( errno == EISDIR ) ) { rc = rmdir( filename ); } @@ -35,11 +33,34 @@ int _PDCLIB_remove( const char * filename ) #endif #ifdef TEST +/* TODO: Work around the following undef */ +#undef SEEK_SET #include <_PDCLIB_test.h> +#include +#include + int main( void ) { - TESTCASE( NO_TESTDRIVER ); + char filename[ L_tmpnam + 6 ] = "touch "; + tmpnam( filename + 6 ); + /* create file */ + system( filename ); + /* file is actually readable */ + TESTCASE( fopen( filename + 6, "r" ) != NULL ); + /* remove function does not return error */ + TESTCASE( _PDCLIB_remove( filename + 6 ) == 0 ); + /* file is no longer readable */ + TESTCASE( fopen( filename + 6, "r" ) == NULL ); + /* remove function does return error */ + TESTCASE( _PDCLIB_remove( filename + 6 ) != 0 ); + memcpy( filename, "mkdir", 5 ); + /* create directory */ + system( filename ); + /* remove function does not return error */ + TESTCASE( _PDCLIB_remove( filename + 6 ) == 0 ); + /* remove function does return error */ + TESTCASE( _PDCLIB_remove( filename + 6 ) != 0 ); return TEST_RESULTS; }