andre@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: andre@0: #include "primpl.h" andre@0: andre@0: PR_IMPLEMENT(PRDir*) PR_OpenDir(const char *name) andre@0: { andre@0: PRDir *dir; andre@0: PRStatus sts; andre@0: andre@0: dir = PR_NEW(PRDir); andre@0: if (dir) { andre@0: sts = _PR_MD_OPEN_DIR(&dir->md,name); andre@0: if (sts != PR_SUCCESS) { andre@0: PR_DELETE(dir); andre@0: return NULL; andre@0: } andre@0: } else { andre@0: PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); andre@0: } andre@0: return dir; andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRDirEntry*) PR_ReadDir(PRDir *dir, PRDirFlags flags) andre@0: { andre@0: /* _MD_READ_DIR return a char* to the name; allocation in machine-dependent code */ andre@0: char* name = _PR_MD_READ_DIR(&dir->md, flags); andre@0: dir->d.name = name; andre@0: return name ? &dir->d : NULL; andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRStatus) PR_CloseDir(PRDir *dir) andre@0: { andre@0: PRInt32 rv; andre@0: andre@0: if (dir) { andre@0: rv = _PR_MD_CLOSE_DIR(&dir->md); andre@0: PR_DELETE(dir); andre@0: if (rv < 0) { andre@0: return PR_FAILURE; andre@0: } else andre@0: return PR_SUCCESS; andre@0: } andre@0: return PR_SUCCESS; andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRStatus) PR_MkDir(const char *name, PRIntn mode) andre@0: { andre@0: PRInt32 rv; andre@0: andre@0: rv = _PR_MD_MKDIR(name, mode); andre@0: if (rv < 0) { andre@0: return PR_FAILURE; andre@0: } else andre@0: return PR_SUCCESS; andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRStatus) PR_MakeDir(const char *name, PRIntn mode) andre@0: { andre@0: PRInt32 rv; andre@0: andre@0: if (!_pr_initialized) _PR_ImplicitInitialization(); andre@0: rv = _PR_MD_MAKE_DIR(name, mode); andre@0: if (rv < 0) { andre@0: return PR_FAILURE; andre@0: } else andre@0: return PR_SUCCESS; andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRStatus) PR_RmDir(const char *name) andre@0: { andre@0: PRInt32 rv; andre@0: andre@0: rv = _PR_MD_RMDIR(name); andre@0: if (rv < 0) { andre@0: return PR_FAILURE; andre@0: } else andre@0: return PR_SUCCESS; andre@0: } andre@0: andre@0: #ifdef MOZ_UNICODE andre@0: /* andre@0: * UTF16 Interface andre@0: */ andre@0: PR_IMPLEMENT(PRDirUTF16*) PR_OpenDirUTF16(const PRUnichar *name) andre@0: { andre@0: PRDirUTF16 *dir; andre@0: PRStatus sts; andre@0: andre@0: dir = PR_NEW(PRDirUTF16); andre@0: if (dir) { andre@0: sts = _PR_MD_OPEN_DIR_UTF16(&dir->md,name); andre@0: if (sts != PR_SUCCESS) { andre@0: PR_DELETE(dir); andre@0: return NULL; andre@0: } andre@0: } else { andre@0: PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); andre@0: } andre@0: return dir; andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRDirEntryUTF16*) PR_ReadDirUTF16(PRDirUTF16 *dir, PRDirFlags flags) andre@0: { andre@0: /* andre@0: * _MD_READ_DIR_UTF16 return a PRUnichar* to the name; allocation in andre@0: * machine-dependent code andre@0: */ andre@0: PRUnichar* name = _PR_MD_READ_DIR_UTF16(&dir->md, flags); andre@0: dir->d.name = name; andre@0: return name ? &dir->d : NULL; andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRStatus) PR_CloseDirUTF16(PRDirUTF16 *dir) andre@0: { andre@0: PRInt32 rv; andre@0: andre@0: if (dir) { andre@0: rv = _PR_MD_CLOSE_DIR_UTF16(&dir->md); andre@0: PR_DELETE(dir); andre@0: if (rv < 0) andre@0: return PR_FAILURE; andre@0: else andre@0: return PR_SUCCESS; andre@0: } andre@0: return PR_SUCCESS; andre@0: } andre@0: andre@0: #endif /* MOZ_UNICODE */