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

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

Minor cleanup.

  • Property mode set to 100644
File size: 1.5 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 "ram.h"
9
10FILE *_opener(int8_t *name, int8_t *mode, uint16_t raw)
11{
12 register FILE *fp;
13 register int16_t plusopt;
14
15 fp = Cbuffs;
16
17 while ( fp->_flags ) {
18
19 if ( ++fp GE (Cbuffs + NSTREAMS))
20 return(NULL);
21 }
22
23 plusopt = mode[1] EQ '+';
24
25 switch (0x007F & *mode) {
26
27 case 'r': /* read mode */
28 if ((fp->_unit = open(name, (plusopt ? O_RDWR : O_RDONLY) | raw)) EQ -1)
29 return(NULL);
30 break;
31
32 case 'w': /* write mode */
33 if ((fp->_unit = open(name, (plusopt ? O_RDWR : O_WRONLY)|O_CREAT|O_TRUNC|raw)) EQ -1)
34 return(NULL);
35
36 break;
37
38 case 'a': /* append mode */
39 if ((fp->_unit = open(name, (plusopt ? O_RDWR : O_WRONLY)|O_CREAT|raw)) EQ -1)
40 return(NULL);
41
42 if (lseek(fp->_unit, 0L, 2) < 0) {
43
44 close(fp->_unit);
45 return(NULL); /* couldn't append */
46 }
47
48 break;
49
50 default:
51 errno = EINVAL;
52 return(NULL);
53 }
54
55 fp->_flags = _BUSY;
56 fp->_buflen = BUFSIZ;
57 fp->_buff = 0;
58 fp->_bend = 0; /* nothing in buffer */
59 fp->_bp = 0;
60 return(fp);
61}
62
63FILE *fopen(int8_t *name, int8_t *mode)
64{
65 return(_opener(name, mode, 0));
66}
67
68FILE *fopena(int8_t *name, int8_t *mode)
69{
70 return(_opener(name, mode, 0));
71}
72
73FILE *fopenb(int8_t *name, int8_t *mode)
74{
75 return(_opener(name, mode, O_RAW));
76}
77
Note: See TracBrowser for help on using the repository browser.