comparison dmd/root.c @ 571:cbd6c8073a32

Changed all '#if linux || __APPLE__' to '#if POSIX' so we can support other platforms too, thanx for the suggestion anders.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Tue, 02 Sep 2008 23:10:12 +0200
parents f79bbd1d0b27
children 50383e476c7e
comparison
equal deleted inserted replaced
568:f75b16f1e405 571:cbd6c8073a32
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 || __APPLE__ 26 #if POSIX
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
374 case ',':
375 #endif*/
376 #if _WIN32 373 #if _WIN32
377 case ';': 374 case ';':
378 #endif 375 #endif
379 #if linux || __APPLE__ 376 #if POSIX
380 case ':': 377 case ':':
381 #endif 378 #endif
382 p++; 379 p++;
383 break; // note that ; cannot appear as part 380 break; // note that ; cannot appear as part
384 // of a path, quotes won't protect it 381 // of a path, quotes won't protect it
388 break; 385 break;
389 386
390 case '\r': 387 case '\r':
391 continue; // ignore carriage returns 388 continue; // ignore carriage returns
392 389
393 #if linux || __APPLE__ 390 #if POSIX
394 case '~': 391 case '~':
395 buf.writestring(getenv("HOME")); 392 buf.writestring(getenv("HOME"));
396 continue; 393 continue;
397 #endif 394 #endif
398 395
712 e = FileName::ext(); 709 e = FileName::ext();
713 if (!e && !ext) 710 if (!e && !ext)
714 return 1; 711 return 1;
715 if (!e || !ext) 712 if (!e || !ext)
716 return 0; 713 return 0;
717 #if linux || __APPLE__ 714 #if POSIX
718 return strcmp(e,ext) == 0; 715 return strcmp(e,ext) == 0;
719 #endif 716 #endif
720 #if _WIN32 717 #if _WIN32
721 return stricmp(e,ext) == 0; 718 return stricmp(e,ext) == 0;
722 #endif 719 #endif
731 File file(this); 728 File file(this);
732 729
733 #if _WIN32 730 #if _WIN32
734 file.touchtime = mem.malloc(sizeof(WIN32_FIND_DATAA)); // keep same file time 731 file.touchtime = mem.malloc(sizeof(WIN32_FIND_DATAA)); // keep same file time
735 #endif 732 #endif
736 #if linux || __APPLE__ 733 #if POSIX
737 file.touchtime = mem.malloc(sizeof(struct stat)); // keep same file time 734 file.touchtime = mem.malloc(sizeof(struct stat)); // keep same file time
738 #endif 735 #endif
739 file.readv(); 736 file.readv();
740 file.name = to; 737 file.name = to;
741 file.writev(); 738 file.writev();
773 return NULL; 770 return NULL;
774 } 771 }
775 772
776 int FileName::exists(const char *name) 773 int FileName::exists(const char *name)
777 { 774 {
778 #if linux || __APPLE__ 775 #if POSIX
779 struct stat st; 776 struct stat st;
780 777
781 if (stat(name, &st) < 0) 778 if (stat(name, &st) < 0)
782 return 0; 779 return 0;
783 if (S_ISDIR(st.st_mode)) 780 if (S_ISDIR(st.st_mode))
820 mem.free(p); 817 mem.free(p);
821 } 818 }
822 #if _WIN32 819 #if _WIN32
823 if (path[strlen(path) - 1] != '\\') 820 if (path[strlen(path) - 1] != '\\')
824 #endif 821 #endif
825 #if linux || __APPLE__ 822 #if POSIX
826 if (path[strlen(path) - 1] != '\\') 823 if (path[strlen(path) - 1] != '\\')
827 #endif 824 #endif
828 { 825 {
829 //printf("mkdir(%s)\n", path); 826 //printf("mkdir(%s)\n", path);
830 #if _WIN32 827 #if _WIN32
831 if (mkdir(path)) 828 if (mkdir(path))
832 #endif 829 #endif
833 #if linux || __APPLE__ 830 #if POSIX
834 if (mkdir(path, 0777)) 831 if (mkdir(path, 0777))
835 #endif 832 #endif
836 error("cannot create directory %s", path); 833 error("cannot create directory %s", path);
837 } 834 }
838 } 835 }
884 /************************************* 881 /*************************************
885 */ 882 */
886 883
887 int File::read() 884 int File::read()
888 { 885 {
889 #if linux || __APPLE__ 886 #if POSIX
890 off_t size; 887 off_t size;
891 ssize_t numread; 888 ssize_t numread;
892 int fd; 889 int fd;
893 struct stat buf; 890 struct stat buf;
894 int result = 0; 891 int result = 0;
1016 * Read a file with memory mapped file I/O. 1013 * Read a file with memory mapped file I/O.
1017 */ 1014 */
1018 1015
1019 int File::mmread() 1016 int File::mmread()
1020 { 1017 {
1021 #if linux || __APPLE__ 1018 #if POSIX
1022 return read(); 1019 return read();
1023 #endif 1020 #endif
1024 #if _WIN32 1021 #if _WIN32
1025 HANDLE hFile; 1022 HANDLE hFile;
1026 HANDLE hFileMap; 1023 HANDLE hFileMap;
1070 * 0 success 1067 * 0 success
1071 */ 1068 */
1072 1069
1073 int File::write() 1070 int File::write()
1074 { 1071 {
1075 #if linux || __APPLE__ 1072 #if POSIX
1076 int fd; 1073 int fd;
1077 ssize_t numwritten; 1074 ssize_t numwritten;
1078 char *name; 1075 char *name;
1079 1076
1080 name = this->name->toChars(); 1077 name = this->name->toChars();
1143 * 0 success 1140 * 0 success
1144 */ 1141 */
1145 1142
1146 int File::append() 1143 int File::append()
1147 { 1144 {
1148 #if linux || __APPLE__ 1145 #if POSIX
1149 return 1; 1146 return 1;
1150 #endif 1147 #endif
1151 #if _WIN32 1148 #if _WIN32
1152 HANDLE h; 1149 HANDLE h;
1153 DWORD numwritten; 1150 DWORD numwritten;
1223 * 2: directory 1220 * 2: directory
1224 */ 1221 */
1225 1222
1226 int File::exists() 1223 int File::exists()
1227 { 1224 {
1228 #if linux || __APPLE__ 1225 #if POSIX
1229 return 0; 1226 return 0;
1230 #endif 1227 #endif
1231 #if _WIN32 1228 #if _WIN32
1232 DWORD dw; 1229 DWORD dw;
1233 int result; 1230 int result;
1248 #endif 1245 #endif
1249 } 1246 }
1250 1247
1251 void File::remove() 1248 void File::remove()
1252 { 1249 {
1253 #if linux || __APPLE__ 1250 #if POSIX
1254 ::remove(this->name->toChars()); 1251 ::remove(this->name->toChars());
1255 #endif 1252 #endif
1256 #if _WIN32 1253 #if _WIN32
1257 DeleteFileA(this->name->toChars()); 1254 DeleteFileA(this->name->toChars());
1258 #endif 1255 #endif
1263 return match(new FileName(n, 0)); 1260 return match(new FileName(n, 0));
1264 } 1261 }
1265 1262
1266 Array *File::match(FileName *n) 1263 Array *File::match(FileName *n)
1267 { 1264 {
1268 #if linux || __APPLE__ 1265 #if POSIX
1269 return NULL; 1266 return NULL;
1270 #endif 1267 #endif
1271 #if _WIN32 1268 #if _WIN32
1272 HANDLE h; 1269 HANDLE h;
1273 WIN32_FIND_DATAA fileinfo; 1270 WIN32_FIND_DATAA fileinfo;
1301 #endif 1298 #endif
1302 } 1299 }
1303 1300
1304 int File::compareTime(File *f) 1301 int File::compareTime(File *f)
1305 { 1302 {
1306 #if linux || __APPLE__ 1303 #if POSIX
1307 return 0; 1304 return 0;
1308 #endif 1305 #endif
1309 #if _WIN32 1306 #if _WIN32
1310 if (!touchtime) 1307 if (!touchtime)
1311 stat(); 1308 stat();
1315 #endif 1312 #endif
1316 } 1313 }
1317 1314
1318 void File::stat() 1315 void File::stat()
1319 { 1316 {
1320 #if linux || __APPLE__ 1317 #if POSIX
1321 if (!touchtime) 1318 if (!touchtime)
1322 { 1319 {
1323 touchtime = mem.calloc(1, sizeof(struct stat)); 1320 touchtime = mem.calloc(1, sizeof(struct stat));
1324 } 1321 }
1325 #endif 1322 #endif
1620 count = _vsnprintf(p,psize,format,args); 1617 count = _vsnprintf(p,psize,format,args);
1621 if (count != -1) 1618 if (count != -1)
1622 break; 1619 break;
1623 psize *= 2; 1620 psize *= 2;
1624 #endif 1621 #endif
1625 #if linux || __APPLE__ 1622 #if POSIX
1626 count = vsnprintf(p,psize,format,args); 1623 count = vsnprintf(p,psize,format,args);
1627 if (count == -1) 1624 if (count == -1)
1628 psize *= 2; 1625 psize *= 2;
1629 else if (count >= psize) 1626 else if (count >= psize)
1630 psize = count + 1; 1627 psize = count + 1;
1652 count = _vsnwprintf(p,psize,format,args); 1649 count = _vsnwprintf(p,psize,format,args);
1653 if (count != -1) 1650 if (count != -1)
1654 break; 1651 break;
1655 psize *= 2; 1652 psize *= 2;
1656 #endif 1653 #endif
1657 #if linux || __APPLE__ 1654 #if POSIX
1658 count = vsnwprintf(p,psize,format,args); 1655 count = vsnwprintf(p,psize,format,args);
1659 if (count == -1) 1656 if (count == -1)
1660 psize *= 2; 1657 psize *= 2;
1661 else if (count >= psize) 1658 else if (count >= psize)
1662 psize = count + 1; 1659 psize = count + 1;