source: trunk/dll/fsopen.c@ 551

Last change on this file since 551 was 551, checked in by Gregg Young, 19 years ago

Indentation cleanup

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