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

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

mercurial