Changeset 3595
- Timestamp:
- Oct 3, 2007, 10:57:48 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kStuff/kRdr/kRdrFile.cpp
r3588 r3595 32 32 #include <k/kHlpAlloc.h> 33 33 #include <k/kHlpString.h> 34 35 #if K_OS == K_OS_OS2 34 #include <k/kErrors.h> 35 36 #if K_OS == K_OS_DARWIN 37 # include <sys/fcntl.h> 38 # include <sys/mman.h> 39 # include <unistd.h> 40 extern int kHlpSys_open(const char *filename, int flags, int mode); /* negated errno */ 41 extern int kHlpSys_close(int fd); 42 extern KSSIZE kHlpSys_read(int fd, void *buf, size_t len); /* negated errno */ 43 extern KI64 kHlpSys_lseek(int fd, int whench, KI64); /* negated errno */ 44 extern void *kHlpSys_mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off); 45 extern int kHlpSys_mprotect(void *addr, size_t len, int prot); 46 extern int kHlpSys_munmap(void *addr, size_t len); 47 48 49 #elif K_OS == K_OS_OS2 36 50 # define INCL_ERRORS 37 51 # define INCL_BASE … … 188 202 KRDR Core; 189 203 /** The file handle. */ 190 #if K_OS == K_OS_OS2 204 #if K_OS == K_OS_DARWIN \ 205 || K_OS == K_OS_LINUX \ 206 || K_OS == K_OS_NETBSD \ 207 || K_OS == K_OS_OPENBSD \ 208 || K_OS == K_OS_SOLARIS 209 int File; 210 #elif K_OS == K_OS_OS2 191 211 HFILE File; 192 212 #elif K_OS == K_OS_WINDOWS … … 373 393 374 394 /** @copydoc KRDROPS::pfnProtect */ 375 static int 395 static int krdrFileProtect(PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments, KBOOL fUnprotectOrProtect) 376 396 { 377 397 PKRDRFILE pRdrFile = (PKRDRFILE)pRdr; … … 556 576 pPrep->cb = (pPrep->cb + (cbPage - 1)) & ~(cbPage- 1); 557 577 558 #if K_OS == K_OS_WINDOWS 578 #if K_OS == K_OS_DARWIN 579 /** @todo */ 580 581 #elif K_OS == K_OS_WINDOWS 559 582 /* 560 583 * The NT memory mapped file API sucks in a lot of ways. Unless you're actually … … 803 826 static KSIZE krdrFilePageSize(PKRDR pRdr) 804 827 { 805 #if K_OS == K_OS_OS2 828 #if K_OS == K_OS_DARWIN 829 return 0x1000; /** @todo find some header somewhere... */ 830 831 #elif K_OS == K_OS_OS2 806 832 /* The page size on OS/2 wont change anytime soon. :-) */ 807 833 return 0x1000; … … 829 855 { 830 856 PKRDRFILE pRdrFile = (PKRDRFILE)pRdr; 831 #if K_OS == K_OS_OS2 || K_OS == K_OS_WINDOWS 857 #if K_OS == K_OS_DARWIN \ 858 || K_OS == K_OS_OS2 \ 859 || K_OS == K_OS_WINDOWS 832 860 return (KIPTR)pRdrFile->File; 833 861 #else … … 847 875 if (pRdrFile->off == -1) 848 876 { 849 #if K_OS == K_OS_OS2 877 #if K_OS == K_OS_DARWIN 878 879 pRdrFile->off = kHlpSys_lseek(pRdrFile->File, SEEK_CUR, 0); 880 if (pRdrFile->off < 0) 881 pRdrFile->off = -1; 882 883 #elif K_OS == K_OS_OS2 850 884 ULONG ulNew; 851 885 APIRET rc = DosSetFilePtr(pRdrFile->File, 0, FILE_CURRENT, &ulNew); … … 889 923 /* check for underflow */ 890 924 if (pRdrFile->cMappings <= 0) 891 #if K_OS == K_OS_OS2 || K_OS == K_OS_WINDOWS 892 return ERROR_INVALID_PARAMETER; 893 #else 894 # error "port me" 895 #endif 925 return KERR_INVALID_PARAMETER; 896 926 897 927 /* decrement usage counter, free mapping if no longer in use. */ … … 920 950 KSIZE cb = (KSIZE)cbFile; 921 951 if (cb != cbFile) 922 return ERROR_NOT_ENOUGH_MEMORY;952 return KERR_NO_MEMORY; 923 953 924 954 pRdrFile->pvMapping = kHlpAlloc(cb); 925 955 if (!pRdrFile->pvMapping) 926 #if K_OS == K_OS_OS2 || K_OS == K_OS_WINDOWS 927 return ERROR_NOT_ENOUGH_MEMORY; 928 #else 929 # error "port me" 930 #endif 956 return KERR_NO_MEMORY; 931 957 rc = pRdrFile->Core.pOps->pfnRead(pRdr, pRdrFile->pvMapping, cb, 0); 932 958 if (rc) … … 955 981 if (pRdrFile->off != off) 956 982 { 957 #if K_OS == K_OS_OS2 983 #if K_OS == K_OS_DARWIN 984 pRdrFile->off = kHlpSys_lseek(pRdrFile->File, SEEK_SET, off); 985 if (pRdrFile->off < 0) 986 { 987 int rc = (int)-pRdrFile->off; 988 pRdrFile->off = -1; 989 return -rc; 990 } 991 992 #elif K_OS == K_OS_OS2 958 993 ULONG ulNew; 959 994 APIRET rc; … … 977 1012 int rc = GetLastError(); 978 1013 if (!rc) 979 rc = ERROR_GEN_FAILURE;1014 rc = KERR_GENERAL_FAILURE; 980 1015 pRdrFile->off = -1; 981 1016 return rc; … … 990 1025 * Do the read. 991 1026 */ 992 #if K_OS == K_OS_OS2 1027 #if K_OS == K_OS_DARWIN 1028 { 1029 KSSIZE cbRead; 1030 1031 cbRead = kHlpSys_read(pRdrFile->File, pvBuf, cb); 1032 if (cbRead != cb) 1033 { 1034 pRdrFile->off = -1; 1035 if (cbRead < 0) 1036 return -cbRead; 1037 return KERR_GENERAL_FAILURE; 1038 } 1039 } 1040 1041 #elif K_OS == K_OS_OS2 993 1042 { 994 1043 ULONG cbRead = 0; … … 1002 1051 { 1003 1052 pRdrFile->off = -1; 1004 return ERROR_GEN_FAILURE;1053 return KERR_GENERAL_FAILURE; 1005 1054 } 1006 1055 } … … 1013 1062 int rc = GetLastError(); 1014 1063 if (!rc) 1015 rc = ERROR_GEN_FAILURE;1064 rc = KERR_GENERAL_FAILURE; 1016 1065 pRdrFile->off = -1; 1017 1066 return rc; … … 1020 1069 { 1021 1070 pRdrFile->off = -1; 1022 return ERROR_GEN_FAILURE;1071 return KERR_GENERAL_FAILURE; 1023 1072 } 1024 1073 } … … 1037 1086 { 1038 1087 PKRDRFILE pRdrFile = (PKRDRFILE)pRdr; 1039 int rc; 1040 #if K_OS == K_OS_OS2 1088 int rc; 1089 1090 #if K_OS == K_OS_DARWIN 1091 rc = kHlpSys_close(pRdrFile->File); 1092 1093 #elif K_OS == K_OS_OS2 1041 1094 rc = DosClose(pRdrFile->File); 1042 1095 … … 1068 1121 1069 1122 /* 1070 * Open the file and determin its size. 1071 */ 1072 #if K_OS == K_OS_OS2 1073 ULONG ulAction = 0; 1074 FILESTATUS3 Info; 1075 APIRET rc; 1076 HFILE File = 0; 1077 KFOFF cb; 1078 char szFilename[CCHMAXPATH]; 1123 * Open the file, determin its size and correct filename. 1124 */ 1125 #if K_OS == K_OS_DARWIN 1126 int File; 1127 KFOFF cb; 1128 KFOFF rc; 1129 char szFilename[1024]; 1130 1131 cchFilename = kHlpStrLen(pszFilename); 1132 if (cchFilename >= sizeof(szFilename)) 1133 return KERR_OUT_OF_RANGE; 1134 kHlpMemCopy(szFilename, pszFilename, cchFilename + 1); 1135 /** @todo normalize the filename. */ 1136 1137 # ifdef O_BINARY 1138 File = kHlpSys_open(pszFilename, O_RDONLY | O_BINARY, 0); 1139 # else 1140 File = kHlpSys_open(pszFilename, O_RDONLY, 0); 1141 # endif 1142 if (File < 0) 1143 return -File; 1144 1145 cb = kHlpSys_lseek(File, SEEK_END, 0); 1146 rc = kHlpSys_lseek(File, SEEK_SET, 0); 1147 if ( cb < 0 1148 || rc < 0) 1149 { 1150 kHlpSys_close(File); 1151 return cb < 0 ? -cb : -rc; 1152 } 1153 1154 #elif K_OS == K_OS_OS2 1155 ULONG ulAction = 0; 1156 FILESTATUS3 Info; 1157 APIRET rc; 1158 HFILE File = 0; 1159 KFOFF cb; 1160 char szFilename[CCHMAXPATH]; 1079 1161 1080 1162 if ((uintptr_t)pszFilename >= 0x20000000) … … 1152 1234 pRdrFile = (PKRDRFILE)kHlpAlloc(sizeof(*pRdrFile) + cchFilename); 1153 1235 if (!pRdrFile) 1154 #if K_OS == K_OS_OS2 1155 { 1236 { 1237 #if K_OS == K_OS_DARWIN 1238 kHlpSys_close(File); 1239 #elif K_OS == K_OS_OS2 1156 1240 DosClose(File); 1157 return ERROR_NOT_ENOUGH_MEMORY;1158 }1159 1241 #elif K_OS == K_OS_WINDOWS 1160 {1161 1242 CloseHandle(File); 1162 return ERROR_NOT_ENOUGH_MEMORY;1163 }1164 1243 #else 1165 1244 # error "port me" 1166 1245 #endif 1246 return KERR_NO_MEMORY; 1247 } 1167 1248 1168 1249 /*
Note:
See TracChangeset
for help on using the changeset viewer.