source: buchla-68k/libcio/close.c@ 018c029

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

No more warnings in libcio.

  • 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 close(fd) -- close file 'fd'
50 =============================================================================
51*/
52
53int16_t close(int16_t fd)
54{
55 register struct channel *chp;
56 register int16_t rc;
57
58 if ((fd < 0) OR (fd > MAXCHAN)) {
59
60 errno = EBADF;
61 return(FAILURE);
62 }
63
64 chp = &chantab[fd]; /* point at the channel */
65
66 rc = (*chp->c_close)(chp->c_arg); /* close the FCB */
67
68 chp->c_read = 0; /* release the channel */
69 chp->c_write = 0;
70 chp->c_ioctl = 0;
71 chp->c_seek = 0;
72 chp->c_close = _badfc;
73
74 if (_fatmod)
75 _clsfat(); /* write modified FAT */
76
77 if (_dirmod)
78 _clsdir(); /* write modified directory */
79
80 return(rc); /* return result of close */
81}
82
83/*
84 =============================================================================
85 _filecl(fp) -- close file 'fp' at the BDOS level
86 =============================================================================
87*/
88
89int16_t _filecl(io_arg arg)
90{
91 struct fcb *fp;
92 register int16_t rc;
93
94 fp = (struct fcb *)arg;
95
96 rc = ClsFile(fp); /* close the FCB */
97 fp->modefl = 0; /* mark the FILE closed */
98 return(rc);
99}
100
101/*
102 =============================================================================
103 _fd_cls() -- close all open files
104 =============================================================================
105*/
106
107void _fd_cls(void)
108{
109 register int16_t fd;
110
111 for (fd = 0; fd < MAXCHAN; ++fd)
112 if (chantab[fd].c_close NE _badfc)
113 close(fd);
114
115 _clsvol(); /* write modified directory adn FAT */
116}
117
Note: See TracBrowser for help on using the repository browser.