|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
|
5 * |
|
6 * This Original Code has been modified by IBM Corporation. Modifications made by IBM |
|
7 * described herein are Copyright (c) International Business Machines Corporation, 2000. |
|
8 * Modifications to Mozilla code or documentation identified per MPL Section 3.3 |
|
9 * |
|
10 * Date Modified by Description of modification |
|
11 * 04/20/2000 IBM Corp. OS/2 build. |
|
12 */ |
|
13 |
|
14 #ifndef _NS_LOCAL_FILE_H_ |
|
15 #define _NS_LOCAL_FILE_H_ |
|
16 |
|
17 #include "nscore.h" |
|
18 |
|
19 #define NS_LOCAL_FILE_CID {0x2e23e220, 0x60be, 0x11d3, {0x8c, 0x4a, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74}} |
|
20 |
|
21 #define NS_DECL_NSLOCALFILE_UNICODE_METHODS \ |
|
22 nsresult AppendUnicode(const char16_t *aNode); \ |
|
23 nsresult GetUnicodeLeafName(char16_t **aLeafName); \ |
|
24 nsresult SetUnicodeLeafName(const char16_t *aLeafName); \ |
|
25 nsresult CopyToUnicode(nsIFile *aNewParentDir, const char16_t *aNewLeafName); \ |
|
26 nsresult CopyToFollowingLinksUnicode(nsIFile *aNewParentDir, const char16_t *aNewLeafName); \ |
|
27 nsresult MoveToUnicode(nsIFile *aNewParentDir, const char16_t *aNewLeafName); \ |
|
28 nsresult GetUnicodeTarget(char16_t **aTarget); \ |
|
29 nsresult GetUnicodePath(char16_t **aPath); \ |
|
30 nsresult InitWithUnicodePath(const char16_t *aPath); \ |
|
31 nsresult AppendRelativeUnicodePath(const char16_t *aRelativePath); |
|
32 |
|
33 // nsXPComInit needs to know about how we are implemented, |
|
34 // so here we will export it. Other users should not depend |
|
35 // on this. |
|
36 |
|
37 #include <errno.h> |
|
38 #include "nsILocalFile.h" |
|
39 |
|
40 #ifdef XP_WIN |
|
41 #include "nsLocalFileWin.h" |
|
42 #elif defined(XP_UNIX) |
|
43 #include "nsLocalFileUnix.h" |
|
44 #else |
|
45 #error NOT_IMPLEMENTED |
|
46 #endif |
|
47 |
|
48 #define NSRESULT_FOR_RETURN(ret) (((ret) < 0) ? NSRESULT_FOR_ERRNO() : NS_OK) |
|
49 |
|
50 inline nsresult |
|
51 nsresultForErrno(int err) |
|
52 { |
|
53 switch (err) { |
|
54 case 0: |
|
55 return NS_OK; |
|
56 #ifdef EDQUOT |
|
57 case EDQUOT: /* Quota exceeded */ |
|
58 // FALLTHROUGH to return NS_ERROR_FILE_DISK_FULL |
|
59 #endif |
|
60 case ENOSPC: |
|
61 return NS_ERROR_FILE_DISK_FULL; |
|
62 #ifdef EISDIR |
|
63 case EISDIR: /* Is a directory. */ |
|
64 return NS_ERROR_FILE_IS_DIRECTORY; |
|
65 #endif |
|
66 case ENAMETOOLONG: |
|
67 return NS_ERROR_FILE_NAME_TOO_LONG; |
|
68 case ENOEXEC: /* Executable file format error. */ |
|
69 return NS_ERROR_FILE_EXECUTION_FAILED; |
|
70 case ENOENT: |
|
71 return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST; |
|
72 case ENOTDIR: |
|
73 return NS_ERROR_FILE_DESTINATION_NOT_DIR; |
|
74 #ifdef ELOOP |
|
75 case ELOOP: |
|
76 return NS_ERROR_FILE_UNRESOLVABLE_SYMLINK; |
|
77 #endif /* ELOOP */ |
|
78 #ifdef ENOLINK |
|
79 case ENOLINK: |
|
80 return NS_ERROR_FILE_UNRESOLVABLE_SYMLINK; |
|
81 #endif /* ENOLINK */ |
|
82 case EEXIST: |
|
83 return NS_ERROR_FILE_ALREADY_EXISTS; |
|
84 #ifdef EPERM |
|
85 case EPERM: |
|
86 #endif /* EPERM */ |
|
87 case EACCES: |
|
88 return NS_ERROR_FILE_ACCESS_DENIED; |
|
89 #ifdef EROFS |
|
90 case EROFS: /* Read-only file system. */ |
|
91 return NS_ERROR_FILE_READ_ONLY; |
|
92 #endif |
|
93 /* |
|
94 * On AIX 4.3, ENOTEMPTY is defined as EEXIST, |
|
95 * so there can't be cases for both without |
|
96 * preprocessing. |
|
97 */ |
|
98 #if ENOTEMPTY != EEXIST |
|
99 case ENOTEMPTY: |
|
100 return NS_ERROR_FILE_DIR_NOT_EMPTY; |
|
101 #endif /* ENOTEMPTY != EEXIST */ |
|
102 /* Note that nsIFile.createUnique() returns |
|
103 NS_ERROR_FILE_TOO_BIG when it cannot create a temporary |
|
104 file with a unique filename. |
|
105 See https://developer.mozilla.org/en-US/docs/Table_Of_Errors |
|
106 Other usages of NS_ERROR_FILE_TOO_BIG in the source tree |
|
107 are in line with the POSIX semantics of EFBIG. |
|
108 So this is a reasonably good approximation. |
|
109 */ |
|
110 case EFBIG: /* File too large. */ |
|
111 return NS_ERROR_FILE_TOO_BIG; |
|
112 |
|
113 default: |
|
114 return NS_ERROR_FAILURE; |
|
115 } |
|
116 } |
|
117 |
|
118 #define NSRESULT_FOR_ERRNO() nsresultForErrno(errno) |
|
119 |
|
120 void NS_StartupLocalFile(); |
|
121 void NS_ShutdownLocalFile(); |
|
122 |
|
123 #endif |