X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=platform%2Fexample%2Ffunctions%2F_PDCLIB%2Fremove.c;h=184a1f2dcf181209a0e4f80b1f224d12e8db2ae4;hb=18af9d0a4cd252433e0cbd5daf4640e325c9d0ab;hp=33963062670202324394ee79637988653a96dc27;hpb=d9dcf16664c81809258992e1653ecb68c8079974;p=pdclib.old diff --git a/platform/example/functions/_PDCLIB/remove.c b/platform/example/functions/_PDCLIB/remove.c index 3396306..184a1f2 100644 --- a/platform/example/functions/_PDCLIB/remove.c +++ b/platform/example/functions/_PDCLIB/remove.c @@ -22,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 ); } @@ -33,11 +33,32 @@ 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[] = "touch testfile"; + 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; }