source: trunk/dll/fsopen.c@ 689

Last change on this file since 689 was 689, checked in by Steven Levine, 18 years ago

Commit OpenWatcom compatibility updates

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