michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: * michael@0: * This Original Code has been modified by IBM Corporation. Modifications made by IBM michael@0: * described herein are Copyright (c) International Business Machines Corporation, 2000. michael@0: * Modifications to Mozilla code or documentation identified per MPL Section 3.3 michael@0: * michael@0: * Date Modified by Description of modification michael@0: * 04/20/2000 IBM Corp. OS/2 build. michael@0: */ michael@0: michael@0: #ifndef _NS_LOCAL_FILE_H_ michael@0: #define _NS_LOCAL_FILE_H_ michael@0: michael@0: #include "nscore.h" michael@0: michael@0: #define NS_LOCAL_FILE_CID {0x2e23e220, 0x60be, 0x11d3, {0x8c, 0x4a, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74}} michael@0: michael@0: #define NS_DECL_NSLOCALFILE_UNICODE_METHODS \ michael@0: nsresult AppendUnicode(const char16_t *aNode); \ michael@0: nsresult GetUnicodeLeafName(char16_t **aLeafName); \ michael@0: nsresult SetUnicodeLeafName(const char16_t *aLeafName); \ michael@0: nsresult CopyToUnicode(nsIFile *aNewParentDir, const char16_t *aNewLeafName); \ michael@0: nsresult CopyToFollowingLinksUnicode(nsIFile *aNewParentDir, const char16_t *aNewLeafName); \ michael@0: nsresult MoveToUnicode(nsIFile *aNewParentDir, const char16_t *aNewLeafName); \ michael@0: nsresult GetUnicodeTarget(char16_t **aTarget); \ michael@0: nsresult GetUnicodePath(char16_t **aPath); \ michael@0: nsresult InitWithUnicodePath(const char16_t *aPath); \ michael@0: nsresult AppendRelativeUnicodePath(const char16_t *aRelativePath); michael@0: michael@0: // nsXPComInit needs to know about how we are implemented, michael@0: // so here we will export it. Other users should not depend michael@0: // on this. michael@0: michael@0: #include michael@0: #include "nsILocalFile.h" michael@0: michael@0: #ifdef XP_WIN michael@0: #include "nsLocalFileWin.h" michael@0: #elif defined(XP_UNIX) michael@0: #include "nsLocalFileUnix.h" michael@0: #else michael@0: #error NOT_IMPLEMENTED michael@0: #endif michael@0: michael@0: #define NSRESULT_FOR_RETURN(ret) (((ret) < 0) ? NSRESULT_FOR_ERRNO() : NS_OK) michael@0: michael@0: inline nsresult michael@0: nsresultForErrno(int err) michael@0: { michael@0: switch (err) { michael@0: case 0: michael@0: return NS_OK; michael@0: #ifdef EDQUOT michael@0: case EDQUOT: /* Quota exceeded */ michael@0: // FALLTHROUGH to return NS_ERROR_FILE_DISK_FULL michael@0: #endif michael@0: case ENOSPC: michael@0: return NS_ERROR_FILE_DISK_FULL; michael@0: #ifdef EISDIR michael@0: case EISDIR: /* Is a directory. */ michael@0: return NS_ERROR_FILE_IS_DIRECTORY; michael@0: #endif michael@0: case ENAMETOOLONG: michael@0: return NS_ERROR_FILE_NAME_TOO_LONG; michael@0: case ENOEXEC: /* Executable file format error. */ michael@0: return NS_ERROR_FILE_EXECUTION_FAILED; michael@0: case ENOENT: michael@0: return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST; michael@0: case ENOTDIR: michael@0: return NS_ERROR_FILE_DESTINATION_NOT_DIR; michael@0: #ifdef ELOOP michael@0: case ELOOP: michael@0: return NS_ERROR_FILE_UNRESOLVABLE_SYMLINK; michael@0: #endif /* ELOOP */ michael@0: #ifdef ENOLINK michael@0: case ENOLINK: michael@0: return NS_ERROR_FILE_UNRESOLVABLE_SYMLINK; michael@0: #endif /* ENOLINK */ michael@0: case EEXIST: michael@0: return NS_ERROR_FILE_ALREADY_EXISTS; michael@0: #ifdef EPERM michael@0: case EPERM: michael@0: #endif /* EPERM */ michael@0: case EACCES: michael@0: return NS_ERROR_FILE_ACCESS_DENIED; michael@0: #ifdef EROFS michael@0: case EROFS: /* Read-only file system. */ michael@0: return NS_ERROR_FILE_READ_ONLY; michael@0: #endif michael@0: /* michael@0: * On AIX 4.3, ENOTEMPTY is defined as EEXIST, michael@0: * so there can't be cases for both without michael@0: * preprocessing. michael@0: */ michael@0: #if ENOTEMPTY != EEXIST michael@0: case ENOTEMPTY: michael@0: return NS_ERROR_FILE_DIR_NOT_EMPTY; michael@0: #endif /* ENOTEMPTY != EEXIST */ michael@0: /* Note that nsIFile.createUnique() returns michael@0: NS_ERROR_FILE_TOO_BIG when it cannot create a temporary michael@0: file with a unique filename. michael@0: See https://developer.mozilla.org/en-US/docs/Table_Of_Errors michael@0: Other usages of NS_ERROR_FILE_TOO_BIG in the source tree michael@0: are in line with the POSIX semantics of EFBIG. michael@0: So this is a reasonably good approximation. michael@0: */ michael@0: case EFBIG: /* File too large. */ michael@0: return NS_ERROR_FILE_TOO_BIG; michael@0: michael@0: default: michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: } michael@0: michael@0: #define NSRESULT_FOR_ERRNO() nsresultForErrno(errno) michael@0: michael@0: void NS_StartupLocalFile(); michael@0: void NS_ShutdownLocalFile(); michael@0: michael@0: #endif