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

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

Point of no return.

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