Mercurial > projects > dstress
changeset 254:a39162afcc94
MSWindows port of "dstress.c"
Carlos Santander <Carlos_member@pathlink.com>
2005-01-27
news:ctbbr2$2qgd$1@digitaldaemon.com
nttp://news.digitalmars.com/digitalmars.D/15204
author | thomask |
---|---|
date | Fri, 28 Jan 2005 11:04:20 +0000 |
parents | 4cf5a45bf77d |
children | 51e4d92ab66e |
files | dstress.c |
diffstat | 1 files changed, 48 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/dstress.c Wed Jan 26 13:58:43 2005 +0000 +++ b/dstress.c Fri Jan 28 11:04:20 2005 +0000 @@ -75,6 +75,10 @@ #endif #ifdef USE_POSIX_LOAD + +#define RETURN_OK 0 +#define RETURN_FAIL 256 + #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -87,10 +91,10 @@ if(0==fstat(file, &fileInfo)){ back=malloc(fileInfo.st_size+1); fileInfo.st_size = read(file, back, fileInfo.st_size); - if(fileInfo.st_size != -1){ + if(fileInfo.st_size>0){ *(back+fileInfo.st_size+1) = '\x00'; }else{ - *back = '\x00'; + back = "\x00"; } } close(file); @@ -99,9 +103,41 @@ return back; } #else + +#ifdef WIN32 + +#define RETURN_OK 0 +#define RETURN_FAIL 1 + +#include <windows.h> +char* loadFile(char* filename){ + char* back=NULL; + DWORD size, numread; + HANDLE file=CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); + if (file != INVALID_HANDLE_VALUE){ + size = GetFileSize(file, NULL); + if (size != INVALID_FILE_SIZE){ + back=malloc((size+1)*sizeof(char)); + if (ReadFile(file,back,size,&numread,NULL) == 0){ + if (numread==size) + *(back+size+1) = '\x00'; + else + back = "\x00"; + }else + back = "\x00"; + } + CloseHandle(file); + } + errno = 0; + return back; +} +#else #error no loadFile adaptation for this system available #endif +#endif + int main(int argc, char* arg[]){ char* compiler; @@ -189,17 +225,17 @@ if(strstr(cmd, "Internal error")!= NULL || strstr(cmd, "gcc.gnu.org/bugs")!=NULL){ printf("ERROR:\t%s (Internal compiler error)\n", arg[2]); }else if(modus==COMPILE){ - if(res==0){ + if(res==RETURN_OK){ printf("PASS: \t%s\n", arg[2]); - }else if(res==256){ + }else if(res==RETURN_FAIL){ printf("FAIL: \t%s [%d]\n", arg[2], res); }else{ printf("ERROR:\t%s [%d]\n", arg[2], res); } }else{ - if(res==256){ + if(res==RETURN_FAIL){ printf("XFAIL:\t%s\n", arg[2]); - }else if(res==0){ + }else if(res==RETURN_OK){ printf("XPASS:\t%s\n", arg[2]); }else{ printf("ERROR:\t%s [%d]\n", arg[2], res); @@ -246,11 +282,11 @@ printf("ERROR:\t%s (Internal compiler error)\n", arg[2]); fprintf(stderr, "\n--------\n"); return 0; - }else if(res==256){ + }else if(res==RETURN_FAIL){ printf("FAIL: \t%s [%d]\n", arg[2], res); fprintf(stderr, "\n--------\n"); return 0; - }else if(res!=0){ + }else if(res!=RETURN_OK){ printf("ERROR:\t%s [%d]\n", arg[2], res); fprintf(stderr, "\n--------\n"); return 0; @@ -272,17 +308,17 @@ } fprintf(stderr, "%s\n", cmd); if(modus==RUN){ - if(res==0){ + if(res==RETURN_OK){ printf("PASS: \t%s\n", arg[2]); - }else if(res==256){ + }else if(res==RETURN_FAIL){ printf("FAIL: \t%s [run: %d]\n", arg[2], res); }else{ printf("ERROR:\t%s [run: %d]\n", arg[2], res); } }else{ - if(res==256){ + if(res==RETURN_FAIL){ printf("XFAIL:\t%s\n", arg[2]); - }else if(res==0){ + }else if(res==RETURN_OK){ printf("XPASS:\t%s [norun: %d]\n", arg[2], res); }else{ printf("ERROR:\t%s [norun: %d]\n", arg[2], res);