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

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

Added include files for global functions and variables.

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[f40a309]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
[6262b5c]8#include "all.h"
[f40a309]9
[7258c6a]10extern int32_t lseek(int16_t fd, int32_t pos, int16_t how);
[f40a309]11
[e225e77]12extern int16_t close(int16_t fd);
13extern int16_t open(int8_t *name, int16_t flag, int16_t mode);
14
[7258c6a]15FILE *_opener(int8_t *name, int8_t *mode, int16_t aflag)
[f40a309]16{
17 register FILE *fp;
[7258c6a]18 register int16_t plusopt;
[f40a309]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 */
[e225e77]33 if ((fp->_unit = open(name, (plusopt ? O_RDWR : O_RDONLY), aflag)) EQ -1)
[f40a309]34 return(NULL);
35 break;
36
37 case 'w': /* write mode */
[e225e77]38 if ((fp->_unit = open(name, (plusopt ? O_RDWR : O_WRONLY)|O_CREAT|O_TRUNC, aflag)) EQ -1)
[f40a309]39 return(NULL);
40
41 break;
42
43 case 'a': /* append mode */
[e225e77]44 if ((fp->_unit = open(name, (plusopt ? O_RDWR : O_WRONLY)|O_CREAT, aflag)) EQ -1)
[f40a309]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*/
[7258c6a]71
[f40a309]72FILE *fopen(int8_t *name, int8_t *mode)
73{
74 return(_opener(name, mode, 0));
75}
[7258c6a]76
[f40a309]77FILE *fopena(int8_t *name, int8_t *mode)
78{
79 return(_opener(name, mode, 0));
80}
[7258c6a]81
[f40a309]82FILE *fopenb(int8_t *name, int8_t *mode)
83{
84 return(_opener(name, mode, O_RAW));
[6262b5c]85}
86
Note: See TracBrowser for help on using the repository browser.