/src/mozilla-central/xpcom/io/nsLocalFile.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #ifndef _NS_LOCAL_FILE_H_ |
8 | | #define _NS_LOCAL_FILE_H_ |
9 | | |
10 | | #include "nscore.h" |
11 | | |
12 | | #define NS_LOCAL_FILE_CID {0x2e23e220, 0x60be, 0x11d3, {0x8c, 0x4a, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74}} |
13 | | |
14 | | #define NS_DECL_NSLOCALFILE_UNICODE_METHODS \ |
15 | | nsresult AppendUnicode(const char16_t *aNode); \ |
16 | | nsresult GetUnicodeLeafName(char16_t **aLeafName); \ |
17 | | nsresult SetUnicodeLeafName(const char16_t *aLeafName); \ |
18 | | nsresult CopyToUnicode(nsIFile *aNewParentDir, const char16_t *aNewLeafName); \ |
19 | | nsresult CopyToFollowingLinksUnicode(nsIFile *aNewParentDir, const char16_t *aNewLeafName); \ |
20 | | nsresult MoveToUnicode(nsIFile *aNewParentDir, const char16_t *aNewLeafName); \ |
21 | | nsresult GetUnicodeTarget(char16_t **aTarget); \ |
22 | | nsresult GetUnicodePath(char16_t **aPath); \ |
23 | | nsresult InitWithUnicodePath(const char16_t *aPath); \ |
24 | | nsresult AppendRelativeUnicodePath(const char16_t *aRelativePath); |
25 | | |
26 | | // XPCOMInit needs to know about how we are implemented, |
27 | | // so here we will export it. Other users should not depend |
28 | | // on this. |
29 | | |
30 | | #include <errno.h> |
31 | | #include "nsIFile.h" |
32 | | |
33 | | #ifdef XP_WIN |
34 | | #include "nsLocalFileWin.h" |
35 | | #elif defined(XP_UNIX) |
36 | | #include "nsLocalFileUnix.h" |
37 | | #else |
38 | | #error NOT_IMPLEMENTED |
39 | | #endif |
40 | | |
41 | 21 | #define NSRESULT_FOR_RETURN(ret) (((ret) < 0) ? NSRESULT_FOR_ERRNO() : NS_OK) |
42 | | |
43 | | inline nsresult |
44 | | nsresultForErrno(int aErr) |
45 | 18 | { |
46 | 18 | switch (aErr) { |
47 | 18 | case 0: |
48 | 3 | return NS_OK; |
49 | 18 | #ifdef EDQUOT |
50 | 18 | case EDQUOT: /* Quota exceeded */ |
51 | 0 | // FALLTHROUGH to return NS_ERROR_FILE_DISK_FULL |
52 | 0 | #endif |
53 | 0 | case ENOSPC: |
54 | 0 | return NS_ERROR_FILE_DISK_FULL; |
55 | 0 | #ifdef EISDIR |
56 | 0 | case EISDIR: /* Is a directory. */ |
57 | 0 | return NS_ERROR_FILE_IS_DIRECTORY; |
58 | 0 | #endif |
59 | 0 | case ENAMETOOLONG: |
60 | 0 | return NS_ERROR_FILE_NAME_TOO_LONG; |
61 | 0 | case ENOEXEC: /* Executable file format error. */ |
62 | 0 | return NS_ERROR_FILE_EXECUTION_FAILED; |
63 | 0 | case ENOENT: |
64 | 0 | return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST; |
65 | 0 | case ENOTDIR: |
66 | 0 | return NS_ERROR_FILE_DESTINATION_NOT_DIR; |
67 | 0 | #ifdef ELOOP |
68 | 0 | case ELOOP: |
69 | 0 | return NS_ERROR_FILE_UNRESOLVABLE_SYMLINK; |
70 | 0 | #endif /* ELOOP */ |
71 | 0 | #ifdef ENOLINK |
72 | 0 | case ENOLINK: |
73 | 0 | return NS_ERROR_FILE_UNRESOLVABLE_SYMLINK; |
74 | 0 | #endif /* ENOLINK */ |
75 | 15 | case EEXIST: |
76 | 15 | return NS_ERROR_FILE_ALREADY_EXISTS; |
77 | 0 | #ifdef EPERM |
78 | 0 | case EPERM: |
79 | 0 | #endif /* EPERM */ |
80 | 0 | case EACCES: |
81 | 0 | return NS_ERROR_FILE_ACCESS_DENIED; |
82 | 0 | #ifdef EROFS |
83 | 0 | case EROFS: /* Read-only file system. */ |
84 | 0 | return NS_ERROR_FILE_READ_ONLY; |
85 | 0 | #endif |
86 | 0 | /* |
87 | 0 | * On AIX 4.3, ENOTEMPTY is defined as EEXIST, |
88 | 0 | * so there can't be cases for both without |
89 | 0 | * preprocessing. |
90 | 0 | */ |
91 | 0 | #if ENOTEMPTY != EEXIST |
92 | 0 | case ENOTEMPTY: |
93 | 0 | return NS_ERROR_FILE_DIR_NOT_EMPTY; |
94 | 0 | #endif /* ENOTEMPTY != EEXIST */ |
95 | 0 | /* Note that nsIFile.createUnique() returns |
96 | 0 | NS_ERROR_FILE_TOO_BIG when it cannot create a temporary |
97 | 0 | file with a unique filename. |
98 | 0 | See https://developer.mozilla.org/en-US/docs/Table_Of_Errors |
99 | 0 | Other usages of NS_ERROR_FILE_TOO_BIG in the source tree |
100 | 0 | are in line with the POSIX semantics of EFBIG. |
101 | 0 | So this is a reasonably good approximation. |
102 | 0 | */ |
103 | 0 | case EFBIG: /* File too large. */ |
104 | 0 | return NS_ERROR_FILE_TOO_BIG; |
105 | 0 |
|
106 | 0 | default: |
107 | 0 | return NS_ERROR_FAILURE; |
108 | 18 | } |
109 | 18 | } |
110 | | |
111 | 18 | #define NSRESULT_FOR_ERRNO() nsresultForErrno(errno) |
112 | | |
113 | | #endif |