source: trunk/dll/fsopen.c@ 2

Last change on this file since 2 was 2, checked in by root, 23 years ago

Initial revision

  • 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 ULONG openflag = OPEN_ACTION_OPEN_IF_EXISTS,openmode = 0,action = 0;
18 HFILE handle;
19 FILE *fp;
20 BOOL text = TRUE;
21
22 if(!stristr(mode,"b"))
23 text = FALSE;
24 if(stristr(mode,"r"))
25 openmode |= OPEN_ACCESS_READONLY;
26 else if(stristr(mode,"w")) {
27 openmode |= OPEN_ACCESS_WRITEONLY;
28 openflag |= (OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW);
29 }
30 if(stristr(mode,"a"))
31 openmode |= OPEN_ACCESS_WRITEONLY;
32 if(stristr(mode,"+")) {
33 openmode &= (~(OPEN_ACCESS_READONLY | OPEN_ACCESS_WRITEONLY));
34 openmode |= OPEN_ACCESS_READWRITE;
35 openflag |= OPEN_ACTION_CREATE_IF_NEW;
36 }
37 if(sharemode == SH_DENYRW)
38 openmode |= OPEN_SHARE_DENYREADWRITE;
39 else if(sharemode == SH_DENYWR)
40 openmode |= OPEN_SHARE_DENYWRITE;
41 else if(sharemode == SH_DENYRD)
42 openmode |= OPEN_SHARE_DENYREAD;
43 else
44 openmode |= OPEN_SHARE_DENYNONE;
45 openmode |= OPEN_FLAGS_FAIL_ON_ERROR;
46 if(text)
47 openmode |= OPEN_FLAGS_SEQUENTIAL;
48 else
49 openmode |= OPEN_FLAGS_RANDOMSEQUENTIAL;
50 if(DosOpen(filename,&handle,&action,0L,FILE_NORMAL,openflag,openmode,
51 (PEAOP2)0))
52 return NULL;
53 if(mode[strlen(mode) - 1] == 't')
54 mode[strlen(mode) - 1] = 0; /* bug bug bug */
55 fp = fdopen(handle,mode);
56 if(!fp) {
57 DosClose(handle);
58 fp = fopen(filename,mode); /* last ditch effort */
59 }
60 if(fp) {
61 if(text) /* line buffer text files */
62 setvbuf(fp,NULL,_IOLBF,BUFSIZ * 2);
63 else
64 setvbuf(fp,NULL,_IOFBF,BUFSIZ * 8);
65 if(stristr(mode,"a"))
66 fseek(fp,0L,SEEK_END);
67 }
68 return fp;
69}
70
Note: See TracBrowser for help on using the repository browser.