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

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

Removed form-feed comments.

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[f40a309]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
[b28a12e]8#include "ram.h"
[f40a309]9
10/*
11 =============================================================================
12 _clsfat() -- write out the modified FAT
13 =============================================================================
14*/
15
[0580615]16void _clsfat(void)
[f40a309]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
[0580615]37void _clsdir(void)
[f40a309]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
[7258c6a]53int16_t close(int16_t fd)
[f40a309]54{
55 register struct channel *chp;
[7258c6a]56 register int16_t rc;
[f40a309]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;
[4a17aeb]72 chp->c_close = _badfc;
[f40a309]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
[7258c6a]89int16_t _filecl(struct fcb *fp)
[f40a309]90{
[7258c6a]91 register int16_t rc;
[f40a309]92
93 rc = ClsFile(fp); /* close the FCB */
94 fp->modefl = 0; /* mark the FILE closed */
95 return(rc);
96}
97
98/*
99 =============================================================================
100 _fd_cls() -- close all open files
101 =============================================================================
102*/
103
[0580615]104void _fd_cls(void)
[f40a309]105{
[7258c6a]106 register int16_t fd;
[f40a309]107
108 for (fd = 0; fd < MAXCHAN; ++fd)
[4a17aeb]109 if (chantab[fd].c_close NE _badfc)
[f40a309]110 close(fd);
111
112 _clsvol(); /* write modified directory adn FAT */
113}
[6262b5c]114
Note: See TracBrowser for help on using the repository browser.