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