source: buchla-68k/orig/IOLIB/FOPEN.C@ 6f49665

Last change on this file since 6f49665 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 1.7 KB
Line 
1/*
2 =============================================================================
3 fopen.c -- open a stream file for the Buchla 700 C I/O Library
4 Version 4 -- 1987-06-30 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#include "stdio.h"
9#include "fcntl.h"
10#include "errno.h"
11#include "stddefs.h"
12
13extern long lseek();
14
15FILE *
16_opener(name, mode, aflag)
17char *name, *mode;
18int aflag;
19{
20 register FILE *fp;
21 register int plusopt;
22
23 fp = Cbuffs;
24
25 while ( fp->_flags ) {
26
27 if ( ++fp GE (Cbuffs + NSTREAMS))
28 return(NULL);
29 }
30
31 plusopt = mode[1] EQ '+';
32
33 switch (0x007F & *mode) {
34
35 case 'r': /* read mode */
36 if ((fp->_unit = open(name, (plusopt ? O_RDWR : O_RDONLY)|aflag)) EQ -1)
37 return(NULL);
38 break;
39
40 case 'w': /* write mode */
41 if ((fp->_unit = open(name, (plusopt ? O_RDWR : O_WRONLY)|aflag|O_CREAT|O_TRUNC)) EQ -1)
42 return(NULL);
43
44 break;
45
46 case 'a': /* append mode */
47 if ((fp->_unit = open(name, (plusopt ? O_RDWR : O_WRONLY)|aflag|O_CREAT)) EQ -1)
48 return(NULL);
49
50 if (lseek(fp->_unit, 0L, 2) < 0) {
51
52 close(fp->_unit);
53 return(NULL); /* couldn't append */
54 }
55
56 break;
57
58 default:
59 errno = EINVAL;
60 return(NULL);
61 }
62
63 fp->_flags = _BUSY;
64 fp->_buflen = BUFSIZ;
65 fp->_buff = 0;
66 fp->_bend = 0; /* nothing in buffer */
67 fp->_bp = 0;
68 return(fp);
69}
70
71/*
72
73*/
74
75FILE *
76fopen(name, mode)
77char *name, *mode;
78{
79 return(_opener(name, mode, 0));
80}
81
82FILE *
83fopena(name, mode)
84char *name, *mode;
85{
86 return(_opener(name, mode, 0));
87}
88
89FILE *
90fopenb(name, mode)
91char *name, *mode;
92{
93 return(_opener(name, mode, O_RAW));
94}
Note: See TracBrowser for help on using the repository browser.