Changeset 551 for trunk/dll/fsopen.c
- Timestamp:
- Feb 28, 2007, 2:33:51 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/fsopen.c
r2 r551 13 13 #pragma alloc_text(FSOPEN,_fsopen) 14 14 15 FILE * _fsopen (CHAR *filename,CHAR *mode,INT sharemode,...) { 15 FILE *_fsopen(CHAR * filename, CHAR * mode, INT sharemode, ...) 16 { 16 17 17 ULONG openflag = OPEN_ACTION_OPEN_IF_EXISTS, openmode = 0,action = 0;18 ULONG openflag = OPEN_ACTION_OPEN_IF_EXISTS, openmode = 0, action = 0; 18 19 HFILE handle; 19 20 FILE *fp; 20 BOOL 21 BOOL text = TRUE; 21 22 22 if (!stristr(mode,"b"))23 if (!stristr(mode, "b")) 23 24 text = FALSE; 24 if (stristr(mode,"r"))25 if (stristr(mode, "r")) 25 26 openmode |= OPEN_ACCESS_READONLY; 26 else if (stristr(mode,"w")) {27 else if (stristr(mode, "w")) { 27 28 openmode |= OPEN_ACCESS_WRITEONLY; 28 29 openflag |= (OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW); 29 30 } 30 if (stristr(mode,"a"))31 if (stristr(mode, "a")) 31 32 openmode |= OPEN_ACCESS_WRITEONLY; 32 if (stristr(mode,"+")) {33 if (stristr(mode, "+")) { 33 34 openmode &= (~(OPEN_ACCESS_READONLY | OPEN_ACCESS_WRITEONLY)); 34 35 openmode |= OPEN_ACCESS_READWRITE; 35 36 openflag |= OPEN_ACTION_CREATE_IF_NEW; 36 37 } 37 if (sharemode == SH_DENYRW)38 if (sharemode == SH_DENYRW) 38 39 openmode |= OPEN_SHARE_DENYREADWRITE; 39 else if (sharemode == SH_DENYWR)40 else if (sharemode == SH_DENYWR) 40 41 openmode |= OPEN_SHARE_DENYWRITE; 41 else if (sharemode == SH_DENYRD)42 else if (sharemode == SH_DENYRD) 42 43 openmode |= OPEN_SHARE_DENYREAD; 43 44 else 44 45 openmode |= OPEN_SHARE_DENYNONE; 45 46 openmode |= OPEN_FLAGS_FAIL_ON_ERROR; 46 if (text)47 if (text) 47 48 openmode |= OPEN_FLAGS_SEQUENTIAL; 48 49 else 49 50 openmode |= OPEN_FLAGS_RANDOMSEQUENTIAL; 50 if (DosOpen(filename,&handle,&action,0L,FILE_NORMAL,openflag,openmode,51 (PEAOP2)0))51 if (DosOpen(filename, &handle, &action, 0L, FILE_NORMAL, openflag, openmode, 52 (PEAOP2) 0)) 52 53 return NULL; 53 if (mode[strlen(mode) - 1] == 't')54 mode[strlen(mode) - 1] = 0; 55 fp = fdopen(handle, mode);56 if (!fp) {54 if (mode[strlen(mode) - 1] == 't') 55 mode[strlen(mode) - 1] = 0; /* bug bug bug */ 56 fp = fdopen(handle, mode); 57 if (!fp) { 57 58 DosClose(handle); 58 fp = fopen(filename, mode);/* last ditch effort */59 fp = fopen(filename, mode); /* last ditch effort */ 59 60 } 60 if (fp) {61 if (text)/* line buffer text files */62 setvbuf(fp, NULL,_IOLBF,BUFSIZ * 2);61 if (fp) { 62 if (text) /* line buffer text files */ 63 setvbuf(fp, NULL, _IOLBF, BUFSIZ * 2); 63 64 else 64 setvbuf(fp, NULL,_IOFBF,BUFSIZ * 8);65 if (stristr(mode,"a"))66 fseek(fp, 0L,SEEK_END);65 setvbuf(fp, NULL, _IOFBF, BUFSIZ * 8); 66 if (stristr(mode, "a")) 67 fseek(fp, 0L, SEEK_END); 67 68 } 68 69 return fp; 69 70 } 70
Note:
See TracChangeset
for help on using the changeset viewer.