source: buchla-68k/libcio/fopen.c@ 5fa506d

Last change on this file since 5fa506d was e225e77, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Added missing includes and declarations.

  • Property mode set to 100644
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 int32_t lseek(int16_t fd, int32_t pos, int16_t how);
14
15extern int16_t close(int16_t fd);
16extern int16_t open(int8_t *name, int16_t flag, int16_t mode);
17
18FILE *_opener(int8_t *name, int8_t *mode, int16_t aflag)
19{
20 register FILE *fp;
21 register int16_t 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)|O_CREAT|O_TRUNC, aflag)) 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)|O_CREAT, aflag)) 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 *fopen(int8_t *name, int8_t *mode)
76{
77 return(_opener(name, mode, 0));
78}
79
80FILE *fopena(int8_t *name, int8_t *mode)
81{
82 return(_opener(name, mode, 0));
83}
84
85FILE *fopenb(int8_t *name, int8_t *mode)
86{
87 return(_opener(name, mode, O_RAW));
88}
Note: See TracBrowser for help on using the repository browser.