nsprpub/pr/src/io/prdir.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/src/io/prdir.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,131 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "primpl.h"
    1.10 +
    1.11 +PR_IMPLEMENT(PRDir*) PR_OpenDir(const char *name)
    1.12 +{
    1.13 +    PRDir *dir;
    1.14 +    PRStatus sts;
    1.15 +
    1.16 +    dir = PR_NEW(PRDir);
    1.17 +    if (dir) {
    1.18 +        sts = _PR_MD_OPEN_DIR(&dir->md,name);
    1.19 +        if (sts != PR_SUCCESS) {
    1.20 +            PR_DELETE(dir);
    1.21 +            return NULL;
    1.22 +        }
    1.23 +    } else {
    1.24 +		PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
    1.25 +	}
    1.26 +    return dir;
    1.27 +}
    1.28 +
    1.29 +PR_IMPLEMENT(PRDirEntry*) PR_ReadDir(PRDir *dir, PRDirFlags flags)
    1.30 +{
    1.31 +    /* _MD_READ_DIR return a char* to the name; allocation in machine-dependent code */
    1.32 +    char* name = _PR_MD_READ_DIR(&dir->md, flags);
    1.33 +    dir->d.name = name;
    1.34 +    return name ? &dir->d : NULL;
    1.35 +}
    1.36 +
    1.37 +PR_IMPLEMENT(PRStatus) PR_CloseDir(PRDir *dir)
    1.38 +{
    1.39 +PRInt32 rv;
    1.40 +
    1.41 +    if (dir) {
    1.42 +        rv = _PR_MD_CLOSE_DIR(&dir->md);
    1.43 +		PR_DELETE(dir);
    1.44 +		if (rv < 0) {
    1.45 +			return PR_FAILURE;
    1.46 +		} else
    1.47 +			return PR_SUCCESS;
    1.48 +    }
    1.49 +	return PR_SUCCESS;
    1.50 +}
    1.51 +
    1.52 +PR_IMPLEMENT(PRStatus) PR_MkDir(const char *name, PRIntn mode)
    1.53 +{
    1.54 +PRInt32 rv;
    1.55 +
    1.56 +	rv = _PR_MD_MKDIR(name, mode);
    1.57 +	if (rv < 0) {
    1.58 +		return PR_FAILURE;
    1.59 +	} else
    1.60 +		return PR_SUCCESS;
    1.61 +}
    1.62 +
    1.63 +PR_IMPLEMENT(PRStatus) PR_MakeDir(const char *name, PRIntn mode)
    1.64 +{
    1.65 +PRInt32 rv;
    1.66 +
    1.67 +	if (!_pr_initialized) _PR_ImplicitInitialization();
    1.68 +	rv = _PR_MD_MAKE_DIR(name, mode);
    1.69 +	if (rv < 0) {
    1.70 +		return PR_FAILURE;
    1.71 +	} else
    1.72 +		return PR_SUCCESS;
    1.73 +}
    1.74 +
    1.75 +PR_IMPLEMENT(PRStatus) PR_RmDir(const char *name)
    1.76 +{
    1.77 +PRInt32 rv;
    1.78 +
    1.79 +	rv = _PR_MD_RMDIR(name);
    1.80 +	if (rv < 0) {
    1.81 +		return PR_FAILURE;
    1.82 +	} else
    1.83 +		return PR_SUCCESS;
    1.84 +}
    1.85 +
    1.86 +#ifdef MOZ_UNICODE
    1.87 +/*
    1.88 + *  UTF16 Interface
    1.89 + */
    1.90 +PR_IMPLEMENT(PRDirUTF16*) PR_OpenDirUTF16(const PRUnichar *name)
    1.91 +{ 
    1.92 +    PRDirUTF16 *dir;
    1.93 +    PRStatus sts;
    1.94 +
    1.95 +    dir = PR_NEW(PRDirUTF16);
    1.96 +    if (dir) {
    1.97 +        sts = _PR_MD_OPEN_DIR_UTF16(&dir->md,name);
    1.98 +        if (sts != PR_SUCCESS) {
    1.99 +            PR_DELETE(dir);
   1.100 +            return NULL;
   1.101 +        }
   1.102 +    } else {
   1.103 +        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
   1.104 +    }
   1.105 +    return dir;
   1.106 +}  
   1.107 + 
   1.108 +PR_IMPLEMENT(PRDirEntryUTF16*) PR_ReadDirUTF16(PRDirUTF16 *dir, PRDirFlags flags)
   1.109 +{ 
   1.110 +    /*
   1.111 +     * _MD_READ_DIR_UTF16 return a PRUnichar* to the name; allocation in
   1.112 +     * machine-dependent code
   1.113 +     */
   1.114 +    PRUnichar* name = _PR_MD_READ_DIR_UTF16(&dir->md, flags);
   1.115 +    dir->d.name = name;
   1.116 +    return name ? &dir->d : NULL;
   1.117 +} 
   1.118 + 
   1.119 +PR_IMPLEMENT(PRStatus) PR_CloseDirUTF16(PRDirUTF16 *dir)
   1.120 +{ 
   1.121 +    PRInt32 rv; 
   1.122 +
   1.123 +    if (dir) {
   1.124 +        rv = _PR_MD_CLOSE_DIR_UTF16(&dir->md);
   1.125 +        PR_DELETE(dir);
   1.126 +        if (rv < 0)
   1.127 +	    return PR_FAILURE;
   1.128 +        else
   1.129 +	    return PR_SUCCESS;
   1.130 +    } 
   1.131 +    return PR_SUCCESS;
   1.132 +}
   1.133 +
   1.134 +#endif /* MOZ_UNICODE */

mercurial