|
|
1.1 root 1: /* cflsbuf.c 1.10 83/05/13 */
2:
3: #include <stdio.h>
4: #include "cpmio.h"
5: #include "cpmfio.h"
6:
7: /*
8: * Flush a full block to floppy disk file
9: * (these routines are never called unless a full block is
10: * to be written)
11: * Create a new extent if required
12: */
13:
14: c_flush(fptr)
15: register C_FILE *fptr;
16: {
17:
18: int it;
19: char alloc();
20:
21: if (!(fptr->c_flag & WRITE)) {
22: fprintf(stderr, "no write access");
23: return (EOF);
24: }
25: fptr->c_seccnt += blksiz/seclth;
26: if (putblock(0xff & (int)fptr->c_dirp->pointers[fptr->c_blk++],
27: fptr->c_base, -1) == EOF)
28: return (EOF);
29: if (fptr->c_blk == 16) {
30: fptr->c_dirp->blkcnt = (char) 0x80;
31: savedir();
32: /* create new extent */
33: if ((it = creext(fptr->c_ext)) == NULL) {
34: fprintf(stderr,"can't create new extent, current: %d\n",
35: fptr->c_ext);
36: return (EOF);
37: }
38: fptr->c_dirp = dirbuf+it;
39: fptr->c_ext = it;
40: fptr->c_blk = 0;
41: fptr->c_seccnt = 0;
42: fptr->c_extno++;
43: fptr->c_dirp->extno= fptr->c_extno;
44: }
45: fptr->c_buf = fptr->c_base;
46: fptr->c_cnt = blksiz;
47: if ((fptr->c_dirp->pointers[fptr->c_blk] = alloc()) == '\0') {
48: fprintf(stderr, "disk full\n");
49: return (EOF);
50: }
51: return (0);
52: }
53:
54: c_flsbuf(c, fptr)
55: register C_FILE *fptr;
56: {
57: if (c_flush(fptr) == EOF)
58: return (EOF);
59: *(fptr->c_buf++) = c;
60: fptr->c_cnt--;
61: return (c);
62: }
63:
64: /*
65: * move the contents of 'buf' into the cpm block buffer,
66: * flush the buffer if full (for binary file transfers)
67: */
68:
69: c_write(fptr, buf, cnt)
70: register C_FILE *fptr;
71: char *buf;
72: {
73: int i = cnt;
74:
75: while (i-- > 0) {
76: *(fptr->c_buf++) = *(buf++);
77: if (--fptr->c_cnt == 0)
78: if (c_flush(fptr) == EOF)
79: return (EOF);
80: }
81: return (cnt);
82: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.