1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/tests/rmdir.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,95 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 +** File: rmdir.c 1.11 +** Description: Demonstrate bugzilla 80884. 1.12 +** 1.13 +** after fix to unix_errors.c, message should report correct 1.14 +** failure of PR_Rmdir(). 1.15 +** 1.16 +** 1.17 +** 1.18 +*/ 1.19 + 1.20 +#include <prio.h> 1.21 +#include <stdio.h> 1.22 +#include <prerror.h> 1.23 +#include <prlog.h> 1.24 +#include "plgetopt.h" 1.25 + 1.26 +#define DIRNAME "xxxBug80884/" 1.27 +#define FILENAME "file80883" 1.28 + 1.29 +PRBool failed_already = PR_FALSE; 1.30 +PRBool debug_mode = PR_FALSE; 1.31 + 1.32 +PRLogModuleInfo *lm; 1.33 + 1.34 +/* 1.35 +** Help() -- print Usage information 1.36 +*/ 1.37 +static void Help( void ) { 1.38 + fprintf(stderr, "template usage:\n" 1.39 + "\t-d debug mode\n" 1.40 + ); 1.41 +} /* --- end Help() */ 1.42 + 1.43 +int main(int argc, char **argv) 1.44 +{ 1.45 + PLOptStatus os; 1.46 + PLOptState *opt = PL_CreateOptState(argc, argv, "dh"); 1.47 + PRFileDesc* fd; 1.48 + PRErrorCode err; 1.49 + 1.50 + /* parse command line options */ 1.51 + while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) { 1.52 + if (PL_OPT_BAD == os) continue; 1.53 + switch (opt->option) { 1.54 + case 'd': /* debug mode */ 1.55 + debug_mode = PR_TRUE; 1.56 + break; 1.57 + case 'h': 1.58 + default: 1.59 + Help(); 1.60 + return 2; 1.61 + } 1.62 + } 1.63 + PL_DestroyOptState(opt); 1.64 + 1.65 + lm = PR_NewLogModule( "testcase" ); 1.66 + 1.67 + (void) PR_MkDir( DIRNAME, 0777); 1.68 + fd = PR_Open( DIRNAME FILENAME, PR_CREATE_FILE|PR_RDWR, 0666); 1.69 + if (fd == 0) { 1.70 + PRErrorCode err = PR_GetError(); 1.71 + fprintf(stderr, "create file fails: %d: %s\n", err, 1.72 + PR_ErrorToString(err, PR_LANGUAGE_I_DEFAULT)); 1.73 + failed_already = PR_TRUE; 1.74 + goto Finished; 1.75 + } 1.76 + 1.77 + PR_Close(fd); 1.78 + 1.79 + if (PR_RmDir( DIRNAME ) == PR_SUCCESS) { 1.80 + fprintf(stderr, "remove directory succeeds\n"); 1.81 + failed_already = PR_TRUE; 1.82 + goto Finished; 1.83 + } 1.84 + 1.85 + err = PR_GetError(); 1.86 + fprintf(stderr, "remove directory fails with: %d: %s\n", err, 1.87 + PR_ErrorToString(err, PR_LANGUAGE_I_DEFAULT)); 1.88 + 1.89 + (void) PR_Delete( DIRNAME FILENAME); 1.90 + (void) PR_RmDir( DIRNAME ); 1.91 + 1.92 + return 0; 1.93 + 1.94 +Finished: 1.95 + if ( debug_mode ) printf("%s\n", ( failed_already ) ? "FAILED" : "PASS" ); 1.96 + return( (failed_already)? 1 : 0 ); 1.97 +} /* --- end main() */ 1.98 +/* --- end template.c */