1 /* $XConsortium: bufio.c,v 1.8 94/04/17 20:17:00 gildea Exp $ */
2 /* $XFree86: xc/lib/font/fontfile/bufio.c,v 3.0 1994/12/17 09:41:39 dawes Exp $ */
6 Copyright (c) 1991 X Consortium
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
16 The above copyright notice and this permission notice shall be included
17 in all copies or substantial portions of the Software.
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 OTHER DEALINGS IN THE SOFTWARE.
27 Except as contained in this notice, the name of the X Consortium shall
28 not be used in advertising or otherwise to promote the sale, use or
29 other dealings in this Software without prior written authorization
30 from the X Consortium.
35 * Author: Keith Packard, MIT X Consortium
48 BufFileCreate (private, io, skip, close)
56 f = (BufFilePtr) xalloc (sizeof *f);
68 #define FileDes(f) ((int) (f)->private)
76 left = read (FileDes(f), (char *)f->buffer, BUFFILESIZE);
82 f->bufp = f->buffer + 1;
87 BufFileRawSkip (f, count)
95 curoff = f->bufp - f->buffer;
96 fileoff = curoff + f->left;
97 if (curoff + count <= fileoff) {
101 todo = count - (fileoff - curoff);
102 if (lseek (FileDes(f), todo, 1) == -1) {
106 curoff = BUFFILESIZE;
109 fileoff = read (FileDes(f), (char *)f->buffer, curoff);
121 BufFileRawClose (f, doClose)
134 /* hv: I'd bet WIN32 has the same effect here */
135 setmode(fd,O_BINARY);
137 return BufFileCreate ((char *) fd, BufFileRawFill, BufFileRawSkip, BufFileRawClose);
141 BufFileRawFlush (c, f)
149 cnt = f->bufp - f->buffer;
151 f->left = BUFFILESIZE;
152 if (write (FileDes(f), (char *)f->buffer, cnt) != cnt)
158 BufFileOpenWrite (fd)
164 /* hv: I'd bet WIN32 has the same effect here */
165 setmode(fd,O_BINARY);
167 f = BufFileCreate ((char *) fd, BufFileRawFlush, 0, BufFileFlush);
169 f->left = BUFFILESIZE;
173 BufFileRead (f, b, n)
189 BufFileWrite (f, b, n)
197 if (BufFilePut (*b++, f) == BUFFILEEOF)
207 if (f->bufp != f->buffer)
208 (*f->io) (BUFFILEEOF, f);
212 BufFileClose (f, doClose)
215 (void) (*f->close) (f, doClose);