source: buchla-68k/libcio/close.c@ 1efe224

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

Prototypes for I/O dispatch pointers.

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 =============================================================================
3 close.c -- close a file for the Buchla 700 C I/O Library
4 Version 9 -- 1987-11-13 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#include "ram.h"
9
10/*
11 =============================================================================
12 _clsfat() -- write out the modified FAT
13 =============================================================================
14*/
15
16void _clsfat(void)
17{
18 /* write the primary FAT to disk */
19
20 BIOS(B_RDWR, 1, _thefat, _thebpb->fsiz,
21 _thebpb->fatrec, 0);
22
23 /* write the secondary FAT to disk */
24
25 BIOS(B_RDWR, 1, _thefat, _thebpb->fsiz,
26 (_thebpb->fatrec - _thebpb->fsiz), 0);
27
28 _fatmod = FALSE; /* FAT on disk now matches memory */
29}
30
31/*
32 =============================================================================
33 _clsdir() -- write out the modified directory
34 =============================================================================
35*/
36
37void _clsdir(void)
38{
39 /* write the directory to disk */
40
41 BIOS(B_RDWR, 1, _thedir, _thebpb->rdlen,
42 (_thebpb->fatrec + _thebpb->fsiz), 0);
43
44 _dirmod = FALSE; /* directory on disk now matches memory */
45}
46
47/*
48
49*/
50
51/*
52 =============================================================================
53 close(fd) -- close file 'fd'
54 =============================================================================
55*/
56
57int16_t close(int16_t fd)
58{
59 register struct channel *chp;
60 register int16_t rc;
61
62 if ((fd < 0) OR (fd > MAXCHAN)) {
63
64 errno = EBADF;
65 return(FAILURE);
66 }
67
68 chp = &chantab[fd]; /* point at the channel */
69
70 rc = (*chp->c_close)(chp->c_arg); /* close the FCB */
71
72 chp->c_read = 0; /* release the channel */
73 chp->c_write = 0;
74 chp->c_ioctl = 0;
75 chp->c_seek = 0;
76 chp->c_close = _badfc;
77
78 if (_fatmod)
79 _clsfat(); /* write modified FAT */
80
81 if (_dirmod)
82 _clsdir(); /* write modified directory */
83
84 return(rc); /* return result of close */
85}
86
87/*
88
89*/
90
91/*
92 =============================================================================
93 _filecl(fp) -- close file 'fp' at the BDOS level
94 =============================================================================
95*/
96
97int16_t _filecl(struct fcb *fp)
98{
99 register int16_t rc;
100
101 rc = ClsFile(fp); /* close the FCB */
102 fp->modefl = 0; /* mark the FILE closed */
103 return(rc);
104}
105
106/*
107 =============================================================================
108 _fd_cls() -- close all open files
109 =============================================================================
110*/
111
112void _fd_cls(void)
113{
114 register int16_t fd;
115
116 for (fd = 0; fd < MAXCHAN; ++fd)
117 if (chantab[fd].c_close NE _badfc)
118 close(fd);
119
120 _clsvol(); /* write modified directory adn FAT */
121}
122
Note: See TracBrowser for help on using the repository browser.