nsprpub/pr/tests/rmdir.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial