Mercurial > projects > ldc
comparison dmd/root.c @ 535:f79bbd1d0b27
Add __APPLE__ to most #if linux compile time switches.
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Sun, 24 Aug 2008 16:54:06 +0200 |
parents | f7ba5f705d59 |
children | cbd6c8073a32 |
comparison
equal
deleted
inserted
replaced
534:7e2867ed70d9 | 535:f79bbd1d0b27 |
---|---|
21 #if _WIN32 | 21 #if _WIN32 |
22 #include <windows.h> | 22 #include <windows.h> |
23 #include <direct.h> | 23 #include <direct.h> |
24 #endif | 24 #endif |
25 | 25 |
26 #if linux | 26 #if linux || __APPLE__ |
27 #include <sys/types.h> | 27 #include <sys/types.h> |
28 #include <sys/stat.h> | 28 #include <sys/stat.h> |
29 #include <fcntl.h> | 29 #include <fcntl.h> |
30 #include <errno.h> | 30 #include <errno.h> |
31 #include <unistd.h> | 31 #include <unistd.h> |
368 { | 368 { |
369 case '"': | 369 case '"': |
370 instring ^= 1; // toggle inside/outside of string | 370 instring ^= 1; // toggle inside/outside of string |
371 continue; | 371 continue; |
372 | 372 |
373 #if MACINTOSH | 373 /*#if MACINTOSH |
374 case ',': | 374 case ',': |
375 #endif | 375 #endif*/ |
376 #if _WIN32 | 376 #if _WIN32 |
377 case ';': | 377 case ';': |
378 #endif | 378 #endif |
379 #if linux | 379 #if linux || __APPLE__ |
380 case ':': | 380 case ':': |
381 #endif | 381 #endif |
382 p++; | 382 p++; |
383 break; // note that ; cannot appear as part | 383 break; // note that ; cannot appear as part |
384 // of a path, quotes won't protect it | 384 // of a path, quotes won't protect it |
388 break; | 388 break; |
389 | 389 |
390 case '\r': | 390 case '\r': |
391 continue; // ignore carriage returns | 391 continue; // ignore carriage returns |
392 | 392 |
393 #if linux | 393 #if linux || __APPLE__ |
394 case '~': | 394 case '~': |
395 buf.writestring(getenv("HOME")); | 395 buf.writestring(getenv("HOME")); |
396 continue; | 396 continue; |
397 #endif | 397 #endif |
398 | 398 |
712 e = FileName::ext(); | 712 e = FileName::ext(); |
713 if (!e && !ext) | 713 if (!e && !ext) |
714 return 1; | 714 return 1; |
715 if (!e || !ext) | 715 if (!e || !ext) |
716 return 0; | 716 return 0; |
717 #if linux | 717 #if linux || __APPLE__ |
718 return strcmp(e,ext) == 0; | 718 return strcmp(e,ext) == 0; |
719 #endif | 719 #endif |
720 #if _WIN32 | 720 #if _WIN32 |
721 return stricmp(e,ext) == 0; | 721 return stricmp(e,ext) == 0; |
722 #endif | 722 #endif |
731 File file(this); | 731 File file(this); |
732 | 732 |
733 #if _WIN32 | 733 #if _WIN32 |
734 file.touchtime = mem.malloc(sizeof(WIN32_FIND_DATAA)); // keep same file time | 734 file.touchtime = mem.malloc(sizeof(WIN32_FIND_DATAA)); // keep same file time |
735 #endif | 735 #endif |
736 #if linux | 736 #if linux || __APPLE__ |
737 file.touchtime = mem.malloc(sizeof(struct stat)); // keep same file time | 737 file.touchtime = mem.malloc(sizeof(struct stat)); // keep same file time |
738 #endif | 738 #endif |
739 file.readv(); | 739 file.readv(); |
740 file.name = to; | 740 file.name = to; |
741 file.writev(); | 741 file.writev(); |
773 return NULL; | 773 return NULL; |
774 } | 774 } |
775 | 775 |
776 int FileName::exists(const char *name) | 776 int FileName::exists(const char *name) |
777 { | 777 { |
778 #if linux | 778 #if linux || __APPLE__ |
779 struct stat st; | 779 struct stat st; |
780 | 780 |
781 if (stat(name, &st) < 0) | 781 if (stat(name, &st) < 0) |
782 return 0; | 782 return 0; |
783 if (S_ISDIR(st.st_mode)) | 783 if (S_ISDIR(st.st_mode)) |
820 mem.free(p); | 820 mem.free(p); |
821 } | 821 } |
822 #if _WIN32 | 822 #if _WIN32 |
823 if (path[strlen(path) - 1] != '\\') | 823 if (path[strlen(path) - 1] != '\\') |
824 #endif | 824 #endif |
825 #if linux | 825 #if linux || __APPLE__ |
826 if (path[strlen(path) - 1] != '\\') | 826 if (path[strlen(path) - 1] != '\\') |
827 #endif | 827 #endif |
828 { | 828 { |
829 //printf("mkdir(%s)\n", path); | 829 //printf("mkdir(%s)\n", path); |
830 #if _WIN32 | 830 #if _WIN32 |
831 if (mkdir(path)) | 831 if (mkdir(path)) |
832 #endif | 832 #endif |
833 #if linux | 833 #if linux || __APPLE__ |
834 if (mkdir(path, 0777)) | 834 if (mkdir(path, 0777)) |
835 #endif | 835 #endif |
836 error("cannot create directory %s", path); | 836 error("cannot create directory %s", path); |
837 } | 837 } |
838 } | 838 } |
884 /************************************* | 884 /************************************* |
885 */ | 885 */ |
886 | 886 |
887 int File::read() | 887 int File::read() |
888 { | 888 { |
889 #if linux | 889 #if linux || __APPLE__ |
890 off_t size; | 890 off_t size; |
891 ssize_t numread; | 891 ssize_t numread; |
892 int fd; | 892 int fd; |
893 struct stat buf; | 893 struct stat buf; |
894 int result = 0; | 894 int result = 0; |
1016 * Read a file with memory mapped file I/O. | 1016 * Read a file with memory mapped file I/O. |
1017 */ | 1017 */ |
1018 | 1018 |
1019 int File::mmread() | 1019 int File::mmread() |
1020 { | 1020 { |
1021 #if linux | 1021 #if linux || __APPLE__ |
1022 return read(); | 1022 return read(); |
1023 #endif | 1023 #endif |
1024 #if _WIN32 | 1024 #if _WIN32 |
1025 HANDLE hFile; | 1025 HANDLE hFile; |
1026 HANDLE hFileMap; | 1026 HANDLE hFileMap; |
1070 * 0 success | 1070 * 0 success |
1071 */ | 1071 */ |
1072 | 1072 |
1073 int File::write() | 1073 int File::write() |
1074 { | 1074 { |
1075 #if linux | 1075 #if linux || __APPLE__ |
1076 int fd; | 1076 int fd; |
1077 ssize_t numwritten; | 1077 ssize_t numwritten; |
1078 char *name; | 1078 char *name; |
1079 | 1079 |
1080 name = this->name->toChars(); | 1080 name = this->name->toChars(); |
1143 * 0 success | 1143 * 0 success |
1144 */ | 1144 */ |
1145 | 1145 |
1146 int File::append() | 1146 int File::append() |
1147 { | 1147 { |
1148 #if linux | 1148 #if linux || __APPLE__ |
1149 return 1; | 1149 return 1; |
1150 #endif | 1150 #endif |
1151 #if _WIN32 | 1151 #if _WIN32 |
1152 HANDLE h; | 1152 HANDLE h; |
1153 DWORD numwritten; | 1153 DWORD numwritten; |
1223 * 2: directory | 1223 * 2: directory |
1224 */ | 1224 */ |
1225 | 1225 |
1226 int File::exists() | 1226 int File::exists() |
1227 { | 1227 { |
1228 #if linux | 1228 #if linux || __APPLE__ |
1229 return 0; | 1229 return 0; |
1230 #endif | 1230 #endif |
1231 #if _WIN32 | 1231 #if _WIN32 |
1232 DWORD dw; | 1232 DWORD dw; |
1233 int result; | 1233 int result; |
1248 #endif | 1248 #endif |
1249 } | 1249 } |
1250 | 1250 |
1251 void File::remove() | 1251 void File::remove() |
1252 { | 1252 { |
1253 #if linux | 1253 #if linux || __APPLE__ |
1254 ::remove(this->name->toChars()); | 1254 ::remove(this->name->toChars()); |
1255 #endif | 1255 #endif |
1256 #if _WIN32 | 1256 #if _WIN32 |
1257 DeleteFileA(this->name->toChars()); | 1257 DeleteFileA(this->name->toChars()); |
1258 #endif | 1258 #endif |
1263 return match(new FileName(n, 0)); | 1263 return match(new FileName(n, 0)); |
1264 } | 1264 } |
1265 | 1265 |
1266 Array *File::match(FileName *n) | 1266 Array *File::match(FileName *n) |
1267 { | 1267 { |
1268 #if linux | 1268 #if linux || __APPLE__ |
1269 return NULL; | 1269 return NULL; |
1270 #endif | 1270 #endif |
1271 #if _WIN32 | 1271 #if _WIN32 |
1272 HANDLE h; | 1272 HANDLE h; |
1273 WIN32_FIND_DATAA fileinfo; | 1273 WIN32_FIND_DATAA fileinfo; |
1301 #endif | 1301 #endif |
1302 } | 1302 } |
1303 | 1303 |
1304 int File::compareTime(File *f) | 1304 int File::compareTime(File *f) |
1305 { | 1305 { |
1306 #if linux | 1306 #if linux || __APPLE__ |
1307 return 0; | 1307 return 0; |
1308 #endif | 1308 #endif |
1309 #if _WIN32 | 1309 #if _WIN32 |
1310 if (!touchtime) | 1310 if (!touchtime) |
1311 stat(); | 1311 stat(); |
1315 #endif | 1315 #endif |
1316 } | 1316 } |
1317 | 1317 |
1318 void File::stat() | 1318 void File::stat() |
1319 { | 1319 { |
1320 #if linux | 1320 #if linux || __APPLE__ |
1321 if (!touchtime) | 1321 if (!touchtime) |
1322 { | 1322 { |
1323 touchtime = mem.calloc(1, sizeof(struct stat)); | 1323 touchtime = mem.calloc(1, sizeof(struct stat)); |
1324 } | 1324 } |
1325 #endif | 1325 #endif |
1620 count = _vsnprintf(p,psize,format,args); | 1620 count = _vsnprintf(p,psize,format,args); |
1621 if (count != -1) | 1621 if (count != -1) |
1622 break; | 1622 break; |
1623 psize *= 2; | 1623 psize *= 2; |
1624 #endif | 1624 #endif |
1625 #if linux | 1625 #if linux || __APPLE__ |
1626 count = vsnprintf(p,psize,format,args); | 1626 count = vsnprintf(p,psize,format,args); |
1627 if (count == -1) | 1627 if (count == -1) |
1628 psize *= 2; | 1628 psize *= 2; |
1629 else if (count >= psize) | 1629 else if (count >= psize) |
1630 psize = count + 1; | 1630 psize = count + 1; |
1652 count = _vsnwprintf(p,psize,format,args); | 1652 count = _vsnwprintf(p,psize,format,args); |
1653 if (count != -1) | 1653 if (count != -1) |
1654 break; | 1654 break; |
1655 psize *= 2; | 1655 psize *= 2; |
1656 #endif | 1656 #endif |
1657 #if linux | 1657 #if linux || __APPLE__ |
1658 count = vsnwprintf(p,psize,format,args); | 1658 count = vsnwprintf(p,psize,format,args); |
1659 if (count == -1) | 1659 if (count == -1) |
1660 psize *= 2; | 1660 psize *= 2; |
1661 else if (count >= psize) | 1661 else if (count >= psize) |
1662 psize = count + 1; | 1662 psize = count + 1; |