source: trunk/dll/fsopen.c@ 1347

Last change on this file since 1347 was 1347, checked in by Gregg Young, 17 years ago

More code cleanup

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.2 KB
RevLine 
[689]1
2/***********************************************************************
3
4 $Id: fsopen.c 1347 2008-12-20 04:22:16Z gyoung $
5
6 _fsopen for IBMC
7
8 Copyright (c) 1993-98 M. Kimes
[1347]9 Copyright (c) 2007 2008 Steven H. Levine
[689]10
11 15 Oct 02 SHL Baseline
12 05 Jun 07 SHL Update for OpenWatcom
13
14***********************************************************************/
15
16#if defined(__IBMC__)
17
[2]18#include <stdlib.h>
19#include <stdio.h>
20#include <string.h>
21#include <io.h>
22#include <fcntl.h>
23#include <share.h>
[907]24
25#define INCL_WIN
26#define INCL_DOS
27#define INCL_LONGLONG
28
[2]29#include "fm3dll.h"
[1178]30#include "stristr.h" // stristr
[2]31
32#pragma alloc_text(FSOPEN,_fsopen)
33
[551]34FILE *_fsopen(CHAR * filename, CHAR * mode, INT sharemode, ...)
35{
[2]36
[841]37 ULONG openflag = OPEN_ACTION_OPEN_IF_EXISTS, openmode = 0;
38 ULONGLONG action = 0;
[2]39 HFILE handle;
40 FILE *fp;
[551]41 BOOL text = TRUE;
[2]42
[551]43 if (!stristr(mode, "b"))
[2]44 text = FALSE;
[551]45 if (stristr(mode, "r"))
[2]46 openmode |= OPEN_ACCESS_READONLY;
[551]47 else if (stristr(mode, "w")) {
[2]48 openmode |= OPEN_ACCESS_WRITEONLY;
49 openflag |= (OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW);
50 }
[551]51 if (stristr(mode, "a"))
[2]52 openmode |= OPEN_ACCESS_WRITEONLY;
[551]53 if (stristr(mode, "+")) {
[2]54 openmode &= (~(OPEN_ACCESS_READONLY | OPEN_ACCESS_WRITEONLY));
55 openmode |= OPEN_ACCESS_READWRITE;
56 openflag |= OPEN_ACTION_CREATE_IF_NEW;
57 }
[551]58 if (sharemode == SH_DENYRW)
[2]59 openmode |= OPEN_SHARE_DENYREADWRITE;
[551]60 else if (sharemode == SH_DENYWR)
[2]61 openmode |= OPEN_SHARE_DENYWRITE;
[551]62 else if (sharemode == SH_DENYRD)
[2]63 openmode |= OPEN_SHARE_DENYREAD;
64 else
65 openmode |= OPEN_SHARE_DENYNONE;
66 openmode |= OPEN_FLAGS_FAIL_ON_ERROR;
[551]67 if (text)
[2]68 openmode |= OPEN_FLAGS_SEQUENTIAL;
69 else
70 openmode |= OPEN_FLAGS_RANDOMSEQUENTIAL;
[844]71 if (DosOpen(filename, &handle, &action, 0, FILE_NORMAL, openflag, openmode,
72 (PEAOP2) 0))
[2]73 return NULL;
[551]74 if (mode[strlen(mode) - 1] == 't')
75 mode[strlen(mode) - 1] = 0; /* bug bug bug */
76 fp = fdopen(handle, mode);
77 if (!fp) {
[2]78 DosClose(handle);
[551]79 fp = fopen(filename, mode); /* last ditch effort */
[2]80 }
[551]81 if (fp) {
82 if (text) /* line buffer text files */
83 setvbuf(fp, NULL, _IOLBF, BUFSIZ * 2);
[2]84 else
[551]85 setvbuf(fp, NULL, _IOFBF, BUFSIZ * 8);
86 if (stristr(mode, "a"))
87 fseek(fp, 0L, SEEK_END);
[2]88 }
89 return fp;
90}
[689]91
92#endif
Note: See TracBrowser for help on using the repository browser.