nsprpub/pr/tests/rmdir.c

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /*
michael@0 7 ** File: rmdir.c
michael@0 8 ** Description: Demonstrate bugzilla 80884.
michael@0 9 **
michael@0 10 ** after fix to unix_errors.c, message should report correct
michael@0 11 ** failure of PR_Rmdir().
michael@0 12 **
michael@0 13 **
michael@0 14 **
michael@0 15 */
michael@0 16
michael@0 17 #include <prio.h>
michael@0 18 #include <stdio.h>
michael@0 19 #include <prerror.h>
michael@0 20 #include <prlog.h>
michael@0 21 #include "plgetopt.h"
michael@0 22
michael@0 23 #define DIRNAME "xxxBug80884/"
michael@0 24 #define FILENAME "file80883"
michael@0 25
michael@0 26 PRBool failed_already = PR_FALSE;
michael@0 27 PRBool debug_mode = PR_FALSE;
michael@0 28
michael@0 29 PRLogModuleInfo *lm;
michael@0 30
michael@0 31 /*
michael@0 32 ** Help() -- print Usage information
michael@0 33 */
michael@0 34 static void Help( void ) {
michael@0 35 fprintf(stderr, "template usage:\n"
michael@0 36 "\t-d debug mode\n"
michael@0 37 );
michael@0 38 } /* --- end Help() */
michael@0 39
michael@0 40 int main(int argc, char **argv)
michael@0 41 {
michael@0 42 PLOptStatus os;
michael@0 43 PLOptState *opt = PL_CreateOptState(argc, argv, "dh");
michael@0 44 PRFileDesc* fd;
michael@0 45 PRErrorCode err;
michael@0 46
michael@0 47 /* parse command line options */
michael@0 48 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) {
michael@0 49 if (PL_OPT_BAD == os) continue;
michael@0 50 switch (opt->option) {
michael@0 51 case 'd': /* debug mode */
michael@0 52 debug_mode = PR_TRUE;
michael@0 53 break;
michael@0 54 case 'h':
michael@0 55 default:
michael@0 56 Help();
michael@0 57 return 2;
michael@0 58 }
michael@0 59 }
michael@0 60 PL_DestroyOptState(opt);
michael@0 61
michael@0 62 lm = PR_NewLogModule( "testcase" );
michael@0 63
michael@0 64 (void) PR_MkDir( DIRNAME, 0777);
michael@0 65 fd = PR_Open( DIRNAME FILENAME, PR_CREATE_FILE|PR_RDWR, 0666);
michael@0 66 if (fd == 0) {
michael@0 67 PRErrorCode err = PR_GetError();
michael@0 68 fprintf(stderr, "create file fails: %d: %s\n", err,
michael@0 69 PR_ErrorToString(err, PR_LANGUAGE_I_DEFAULT));
michael@0 70 failed_already = PR_TRUE;
michael@0 71 goto Finished;
michael@0 72 }
michael@0 73
michael@0 74 PR_Close(fd);
michael@0 75
michael@0 76 if (PR_RmDir( DIRNAME ) == PR_SUCCESS) {
michael@0 77 fprintf(stderr, "remove directory succeeds\n");
michael@0 78 failed_already = PR_TRUE;
michael@0 79 goto Finished;
michael@0 80 }
michael@0 81
michael@0 82 err = PR_GetError();
michael@0 83 fprintf(stderr, "remove directory fails with: %d: %s\n", err,
michael@0 84 PR_ErrorToString(err, PR_LANGUAGE_I_DEFAULT));
michael@0 85
michael@0 86 (void) PR_Delete( DIRNAME FILENAME);
michael@0 87 (void) PR_RmDir( DIRNAME );
michael@0 88
michael@0 89 return 0;
michael@0 90
michael@0 91 Finished:
michael@0 92 if ( debug_mode ) printf("%s\n", ( failed_already ) ? "FAILED" : "PASS" );
michael@0 93 return( (failed_already)? 1 : 0 );
michael@0 94 } /* --- end main() */
michael@0 95 /* --- end template.c */

mercurial