nsprpub/pr/src/io/prdir.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

     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 #include "primpl.h"
     8 PR_IMPLEMENT(PRDir*) PR_OpenDir(const char *name)
     9 {
    10     PRDir *dir;
    11     PRStatus sts;
    13     dir = PR_NEW(PRDir);
    14     if (dir) {
    15         sts = _PR_MD_OPEN_DIR(&dir->md,name);
    16         if (sts != PR_SUCCESS) {
    17             PR_DELETE(dir);
    18             return NULL;
    19         }
    20     } else {
    21 		PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
    22 	}
    23     return dir;
    24 }
    26 PR_IMPLEMENT(PRDirEntry*) PR_ReadDir(PRDir *dir, PRDirFlags flags)
    27 {
    28     /* _MD_READ_DIR return a char* to the name; allocation in machine-dependent code */
    29     char* name = _PR_MD_READ_DIR(&dir->md, flags);
    30     dir->d.name = name;
    31     return name ? &dir->d : NULL;
    32 }
    34 PR_IMPLEMENT(PRStatus) PR_CloseDir(PRDir *dir)
    35 {
    36 PRInt32 rv;
    38     if (dir) {
    39         rv = _PR_MD_CLOSE_DIR(&dir->md);
    40 		PR_DELETE(dir);
    41 		if (rv < 0) {
    42 			return PR_FAILURE;
    43 		} else
    44 			return PR_SUCCESS;
    45     }
    46 	return PR_SUCCESS;
    47 }
    49 PR_IMPLEMENT(PRStatus) PR_MkDir(const char *name, PRIntn mode)
    50 {
    51 PRInt32 rv;
    53 	rv = _PR_MD_MKDIR(name, mode);
    54 	if (rv < 0) {
    55 		return PR_FAILURE;
    56 	} else
    57 		return PR_SUCCESS;
    58 }
    60 PR_IMPLEMENT(PRStatus) PR_MakeDir(const char *name, PRIntn mode)
    61 {
    62 PRInt32 rv;
    64 	if (!_pr_initialized) _PR_ImplicitInitialization();
    65 	rv = _PR_MD_MAKE_DIR(name, mode);
    66 	if (rv < 0) {
    67 		return PR_FAILURE;
    68 	} else
    69 		return PR_SUCCESS;
    70 }
    72 PR_IMPLEMENT(PRStatus) PR_RmDir(const char *name)
    73 {
    74 PRInt32 rv;
    76 	rv = _PR_MD_RMDIR(name);
    77 	if (rv < 0) {
    78 		return PR_FAILURE;
    79 	} else
    80 		return PR_SUCCESS;
    81 }
    83 #ifdef MOZ_UNICODE
    84 /*
    85  *  UTF16 Interface
    86  */
    87 PR_IMPLEMENT(PRDirUTF16*) PR_OpenDirUTF16(const PRUnichar *name)
    88 { 
    89     PRDirUTF16 *dir;
    90     PRStatus sts;
    92     dir = PR_NEW(PRDirUTF16);
    93     if (dir) {
    94         sts = _PR_MD_OPEN_DIR_UTF16(&dir->md,name);
    95         if (sts != PR_SUCCESS) {
    96             PR_DELETE(dir);
    97             return NULL;
    98         }
    99     } else {
   100         PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
   101     }
   102     return dir;
   103 }  
   105 PR_IMPLEMENT(PRDirEntryUTF16*) PR_ReadDirUTF16(PRDirUTF16 *dir, PRDirFlags flags)
   106 { 
   107     /*
   108      * _MD_READ_DIR_UTF16 return a PRUnichar* to the name; allocation in
   109      * machine-dependent code
   110      */
   111     PRUnichar* name = _PR_MD_READ_DIR_UTF16(&dir->md, flags);
   112     dir->d.name = name;
   113     return name ? &dir->d : NULL;
   114 } 
   116 PR_IMPLEMENT(PRStatus) PR_CloseDirUTF16(PRDirUTF16 *dir)
   117 { 
   118     PRInt32 rv; 
   120     if (dir) {
   121         rv = _PR_MD_CLOSE_DIR_UTF16(&dir->md);
   122         PR_DELETE(dir);
   123         if (rv < 0)
   124 	    return PR_FAILURE;
   125         else
   126 	    return PR_SUCCESS;
   127     } 
   128     return PR_SUCCESS;
   129 }
   131 #endif /* MOZ_UNICODE */

mercurial