michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: ** File: rmdir.c michael@0: ** Description: Demonstrate bugzilla 80884. michael@0: ** michael@0: ** after fix to unix_errors.c, message should report correct michael@0: ** failure of PR_Rmdir(). michael@0: ** michael@0: ** michael@0: ** michael@0: */ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include "plgetopt.h" michael@0: michael@0: #define DIRNAME "xxxBug80884/" michael@0: #define FILENAME "file80883" michael@0: michael@0: PRBool failed_already = PR_FALSE; michael@0: PRBool debug_mode = PR_FALSE; michael@0: michael@0: PRLogModuleInfo *lm; michael@0: michael@0: /* michael@0: ** Help() -- print Usage information michael@0: */ michael@0: static void Help( void ) { michael@0: fprintf(stderr, "template usage:\n" michael@0: "\t-d debug mode\n" michael@0: ); michael@0: } /* --- end Help() */ michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: PLOptStatus os; michael@0: PLOptState *opt = PL_CreateOptState(argc, argv, "dh"); michael@0: PRFileDesc* fd; michael@0: PRErrorCode err; michael@0: michael@0: /* parse command line options */ michael@0: while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) { michael@0: if (PL_OPT_BAD == os) continue; michael@0: switch (opt->option) { michael@0: case 'd': /* debug mode */ michael@0: debug_mode = PR_TRUE; michael@0: break; michael@0: case 'h': michael@0: default: michael@0: Help(); michael@0: return 2; michael@0: } michael@0: } michael@0: PL_DestroyOptState(opt); michael@0: michael@0: lm = PR_NewLogModule( "testcase" ); michael@0: michael@0: (void) PR_MkDir( DIRNAME, 0777); michael@0: fd = PR_Open( DIRNAME FILENAME, PR_CREATE_FILE|PR_RDWR, 0666); michael@0: if (fd == 0) { michael@0: PRErrorCode err = PR_GetError(); michael@0: fprintf(stderr, "create file fails: %d: %s\n", err, michael@0: PR_ErrorToString(err, PR_LANGUAGE_I_DEFAULT)); michael@0: failed_already = PR_TRUE; michael@0: goto Finished; michael@0: } michael@0: michael@0: PR_Close(fd); michael@0: michael@0: if (PR_RmDir( DIRNAME ) == PR_SUCCESS) { michael@0: fprintf(stderr, "remove directory succeeds\n"); michael@0: failed_already = PR_TRUE; michael@0: goto Finished; michael@0: } michael@0: michael@0: err = PR_GetError(); michael@0: fprintf(stderr, "remove directory fails with: %d: %s\n", err, michael@0: PR_ErrorToString(err, PR_LANGUAGE_I_DEFAULT)); michael@0: michael@0: (void) PR_Delete( DIRNAME FILENAME); michael@0: (void) PR_RmDir( DIRNAME ); michael@0: michael@0: return 0; michael@0: michael@0: Finished: michael@0: if ( debug_mode ) printf("%s\n", ( failed_already ) ? "FAILED" : "PASS" ); michael@0: return( (failed_already)? 1 : 0 ); michael@0: } /* --- end main() */ michael@0: /* --- end template.c */