Vault
4.1
|
00001 /* 00002 Copyright c1997-2014 Trygve Isaacson. All rights reserved. 00003 This file is part of the Code Vault version 4.1 00004 http://www.bombaydigital.com/ 00005 License: MIT. See LICENSE.md in the Vault top level directory. 00006 */ 00007 00010 #include "vtypes.h" 00011 00012 #include "vstring.h" 00013 #include "vexception.h" 00014 #include "vtypes_internal.h" 00015 00016 #include <errno.h> 00017 00018 Vs64 vault::VgetMemoryUsage() { 00019 return 0; // FIXME - find an API to use on Mac 00020 } 00021 00022 // On Mac OS X, it is usually most convenient if we use Unix line endings 00023 // (0x0A) rather than Classic Mac OS 9 line endings (0x0D), because many 00024 // of the Unix tools barf on Classic line endings. 00025 00026 static const Vu8 kUnixLineEnding = 0x0A; 00027 00028 const Vu8* vault::VgetNativeLineEnding(int& numBytes) { 00029 numBytes = 1; 00030 return &kUnixLineEnding; 00031 } 00032 00033 // VSystemError --------------------------------------------------------------- 00034 // Platform-specific implementation of VSystemError internal accessors. 00035 00036 // static 00037 int VSystemError::_getSystemErrorCode() { 00038 return errno; 00039 } 00040 00041 // static 00042 int VSystemError::_getSocketErrorCode() { 00043 return errno; 00044 } 00045 00046 // static 00047 VString VSystemError::_getSystemErrorMessage(int errorCode) { 00048 return ::strerror(errorCode); 00049 } 00050 00051 bool VSystemError::_isLikePosixError(int posixErrorCode) const { 00052 // We are POSIX. No translation necessary. 00053 return (posixErrorCode == mErrorCode); 00054 } 00055 00056 // VPlatformAPI ----------------------------------------------------------------- 00057 00058 // static 00059 VString VPlatformAPI::getcwd() { 00060 VString result; 00061 result.preflight(PATH_MAX); 00062 char* cwdResult = vault::getcwd(result.buffer(), PATH_MAX); 00063 if (cwdResult == NULL) { 00064 throw VException(VSystemError(), "Call to getcwd failed."); 00065 } 00066 00067 result.postflight((int) ::strlen(cwdResult)); 00068 return result; 00069 } 00070 00071 // static 00072 int VPlatformAPI::open(const VString& path, int flags, mode_t mode) { 00073 return vault::open(path, flags, mode); 00074 } 00075 00076 // static 00077 FILE* VPlatformAPI::fopen(const VString& path, const char* mode) { 00078 return vault::fopen(path, mode); 00079 } 00080 00081 // static 00082 int VPlatformAPI::mkdir(const VString& path, mode_t mode) { 00083 return vault::mkdir(path, mode); 00084 } 00085 00086 // static 00087 int VPlatformAPI::rmdir(const VString& path) { 00088 return vault::rmdir(path); 00089 } 00090 00091 // static 00092 int VPlatformAPI::unlink(const VString& path) { 00093 return vault::unlink(path); 00094 } 00095 00096 // static 00097 int VPlatformAPI::rename(const VString& oldName, const VString& newName) { 00098 return vault::rename(oldName, newName); 00099 } 00100 00101 // static 00102 int VPlatformAPI::stat(const VString& path, struct stat* buf) { 00103 return vault::stat(path, buf); 00104 } 00105