Bug 1867190 - Add prefs for PHC probablities r=glandium
[gecko.git] / xpcom / io / nsLocalFile.h
blob779b2e6c95807adfd2482546a0b89be0ec11ea6c
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_
10 #include "nscore.h"
12 #define NS_LOCAL_FILE_CID \
13 { \
14 0x2e23e220, 0x60be, 0x11d3, { \
15 0x8c, 0x4a, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74 \
16 } \
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
36 // on this.
38 #include <errno.h>
39 #include "nsIFile.h"
41 #ifdef XP_WIN
42 # include "nsLocalFileWin.h"
43 #elif defined(XP_UNIX)
44 # include "nsLocalFileUnix.h"
45 #else
46 # error NOT_IMPLEMENTED
47 #endif
49 #define NSRESULT_FOR_RETURN(ret) (((ret) < 0) ? NSRESULT_FOR_ERRNO() : NS_OK)
51 inline nsresult nsresultForErrno(int aErr) {
52 switch (aErr) {
53 case 0:
54 return NS_OK;
55 #ifdef EDQUOT
56 case EDQUOT: /* Quota exceeded */
57 [[fallthrough]]; // to NS_ERROR_FILE_NO_DEVICE_SPACE
58 #endif
59 case ENOSPC:
60 return NS_ERROR_FILE_NO_DEVICE_SPACE;
61 #ifdef EISDIR
62 case EISDIR: /* Is a directory. */
63 return NS_ERROR_FILE_IS_DIRECTORY;
64 #endif
65 case ENAMETOOLONG:
66 return NS_ERROR_FILE_NAME_TOO_LONG;
67 case ENOEXEC: /* Executable file format error. */
68 return NS_ERROR_FILE_EXECUTION_FAILED;
69 case ENOENT:
70 return NS_ERROR_FILE_NOT_FOUND;
71 case ENOTDIR:
72 return NS_ERROR_FILE_DESTINATION_NOT_DIR;
73 #ifdef ELOOP
74 case ELOOP:
75 return NS_ERROR_FILE_UNRESOLVABLE_SYMLINK;
76 #endif /* ELOOP */
77 #ifdef ENOLINK
78 case ENOLINK:
79 return NS_ERROR_FILE_UNRESOLVABLE_SYMLINK;
80 #endif /* ENOLINK */
81 case EEXIST:
82 return NS_ERROR_FILE_ALREADY_EXISTS;
83 #ifdef EPERM
84 case EPERM:
85 #endif /* EPERM */
86 case EACCES:
87 return NS_ERROR_FILE_ACCESS_DENIED;
88 #ifdef EROFS
89 case EROFS: /* Read-only file system. */
90 return NS_ERROR_FILE_READ_ONLY;
91 #endif
93 * On AIX 4.3, ENOTEMPTY is defined as EEXIST,
94 * so there can't be cases for both without
95 * preprocessing.
97 #if ENOTEMPTY != EEXIST
98 case ENOTEMPTY:
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;
112 #ifdef ENOATTR
113 case ENOATTR:
114 return NS_ERROR_NOT_AVAILABLE;
115 #endif // ENOATTR
117 default:
118 return NS_ERROR_FAILURE;
122 #define NSRESULT_FOR_ERRNO() nsresultForErrno(errno)
124 #endif