|
|
1.1 root 1:
2: /*
3: * oswrite( mode,recsiz,ioptr,scptr ) writes the record in scblk to
4: * the designated output file. there are two types of transfers:
5: *
6: * unbuffered write is done immediately
7: *
8: * buffered write is done into buffer
9: *
10: * in either case, a new-line is appended to the record if in
11: * line mode (mode > 0)
12: */
13:
14: #include "spitblks.h"
15: #include "spitio.h"
16:
17: int
18: oswrite( mode, recsiz, ioptr, scptr )
19:
20: int mode;
21: register int recsiz;
22: struct ioblk *ioptr;
23: struct scblk *scptr;
24:
25: {
26: char *saveloc, savech;
27: register char *cp = scptr -> str;
28: register int fdn = ioptr -> fdn;
29: int ioerrcnt = 0;
30:
31: /*
32: * if in line mode, save the character after the string
33: * requested to be written and insert a new-line
34: */
35: if ( mode > 0 ) {
36: saveloc = cp + recsiz;
37: savech = *saveloc;
38: *saveloc = '\n';
39: recsiz++;
40: }
41:
42: /* if unbuffered, write the string directly to the output */
43: if ( ioptr -> flg & IO_WRC ) {
44: if ( write( fdn, cp, recsiz ) != recsiz)
45: ioerrcnt++;
46:
47: } else { /* buffered */
48: register struct bfblk *bfptr = ioptr -> buf;
49:
50: while (recsiz > 0) {
51: register int n = recsiz;
52:
53: if ( n > bfptr -> rem )
54: n = bfptr -> rem;
55:
56: recsiz -= n;
57:
58: if ( n == bfptr -> siz ) {
59: if ( write ( fdn, cp, n ) != n)
60: ioerrcnt++;
61: cp += n;
62: } else {
63: register char *r = bfptr -> buf + bfptr -> off;
64: bfptr -> off += n;
65: bfptr -> rem -= n;
66:
67: /* copy n characters from *cp to *r */
68: if ( n & 1 )
69: *r++ = *cp++;
70: n >>= 1;
71: while (--n >= 0) {
72: *r++ = *cp++;
73: *r++ = *cp++;
74: }
75:
76: if ( bfptr -> rem == 0 )
77: ioerrcnt += flush( ioptr );
78: }
79: }
80:
81: }
82:
83: /* if line mode, restore the previously saved character */
84: if ( mode > 0 )
85: *saveloc = savech;
86:
87: return ioerrcnt;
88: }
89:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.