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