1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef _NS_LOCAL_FILE_H_
8 #define _NS_LOCAL_FILE_H_
12 #define NS_LOCAL_FILE_CID \
14 0x2e23e220, 0x60be, 0x11d3, { \
15 0x8c, 0x4a, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74 \
19 #define NS_DECL_NSLOCALFILE_UNICODE_METHODS \
20 nsresult AppendUnicode(const char16_t* aNode); \
21 nsresult GetUnicodeLeafName(char16_t** aLeafName); \
22 nsresult SetUnicodeLeafName(const char16_t* aLeafName); \
23 nsresult CopyToUnicode(nsIFile* aNewParentDir, \
24 const char16_t* aNewLeafName); \
25 nsresult CopyToFollowingLinksUnicode(nsIFile* aNewParentDir, \
26 const char16_t* aNewLeafName); \
27 nsresult MoveToUnicode(nsIFile* aNewParentDir, \
28 const char16_t* aNewLeafName); \
29 nsresult GetUnicodeTarget(char16_t** aTarget); \
30 nsresult GetUnicodePath(char16_t** aPath); \
31 nsresult InitWithUnicodePath(const char16_t* aPath); \
32 nsresult AppendRelativeUnicodePath(const char16_t* aRelativePath);
34 // XPCOMInit needs to know about how we are implemented,
35 // so here we will export it. Other users should not depend
42 # include "nsLocalFileWin.h"
43 #elif defined(XP_UNIX)
44 # include "nsLocalFileUnix.h"
46 # error NOT_IMPLEMENTED
49 #define NSRESULT_FOR_RETURN(ret) (((ret) < 0) ? NSRESULT_FOR_ERRNO() : NS_OK)
51 inline nsresult
nsresultForErrno(int aErr
) {
56 case EDQUOT
: /* Quota exceeded */
57 [[fallthrough
]]; // to NS_ERROR_FILE_NO_DEVICE_SPACE
60 return NS_ERROR_FILE_NO_DEVICE_SPACE
;
62 case EISDIR
: /* Is a directory. */
63 return NS_ERROR_FILE_IS_DIRECTORY
;
66 return NS_ERROR_FILE_NAME_TOO_LONG
;
67 case ENOEXEC
: /* Executable file format error. */
68 return NS_ERROR_FILE_EXECUTION_FAILED
;
70 return NS_ERROR_FILE_NOT_FOUND
;
72 return NS_ERROR_FILE_DESTINATION_NOT_DIR
;
75 return NS_ERROR_FILE_UNRESOLVABLE_SYMLINK
;
79 return NS_ERROR_FILE_UNRESOLVABLE_SYMLINK
;
82 return NS_ERROR_FILE_ALREADY_EXISTS
;
87 return NS_ERROR_FILE_ACCESS_DENIED
;
89 case EROFS
: /* Read-only file system. */
90 return NS_ERROR_FILE_READ_ONLY
;
93 * On AIX 4.3, ENOTEMPTY is defined as EEXIST,
94 * so there can't be cases for both without
97 #if ENOTEMPTY != EEXIST
99 return NS_ERROR_FILE_DIR_NOT_EMPTY
;
100 #endif /* ENOTEMPTY != EEXIST */
101 /* Note that nsIFile.createUnique() returns
102 NS_ERROR_FILE_TOO_BIG when it cannot create a temporary
103 file with a unique filename.
104 See https://developer.mozilla.org/en-US/docs/Table_Of_Errors
105 Other usages of NS_ERROR_FILE_TOO_BIG in the source tree
106 are in line with the POSIX semantics of EFBIG.
107 So this is a reasonably good approximation.
109 case EFBIG
: /* File too large. */
110 return NS_ERROR_FILE_TOO_BIG
;
114 return NS_ERROR_NOT_AVAILABLE
;
118 return NS_ERROR_FAILURE
;
122 #define NSRESULT_FOR_ERRNO() nsresultForErrno(errno)