3 Copyright 1991, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall
23 not be used in advertising or otherwise to promote the sale, use or
24 other dealings in this Software without prior written authorization
30 * Author: Keith Packard, MIT X Consortium
38 #include <X11/fonts/fontmisc.h>
39 #include <X11/fonts/bufio.h>
43 BufFileCreate (char *private,
44 int (*input)(BufFilePtr),
45 int (*output)(int, BufFilePtr),
46 int (*skip)(BufFilePtr, int),
47 int (*close)(BufFilePtr, int))
51 f = malloc (sizeof *f);
65 #define FileDes(f) ((int)(long) (f)->private)
68 BufFileRawFill (BufFilePtr f)
72 left = read (FileDes(f), (char *)f->buffer, BUFFILESIZE);
78 f->bufp = f->buffer + 1;
83 BufFileRawSkip (BufFilePtr f, int count)
89 curoff = f->bufp - f->buffer;
90 fileoff = curoff + f->left;
91 if (curoff + count <= fileoff) {
95 todo = count - (fileoff - curoff);
96 if (lseek (FileDes(f), todo, 1) == -1) {
100 curoff = BUFFILESIZE;
103 fileoff = read (FileDes(f), (char *)f->buffer, curoff);
115 BufFileRawClose (BufFilePtr f, int doClose)
123 BufFileOpenRead (int fd)
126 /* hv: I'd bet WIN32 has the same effect here */
127 setmode(fd,O_BINARY);
129 return BufFileCreate ((char *)(long) fd, BufFileRawFill, 0, BufFileRawSkip, BufFileRawClose);
133 BufFileRawFlush (int c, BufFilePtr f)
139 cnt = f->bufp - f->buffer;
141 f->left = BUFFILESIZE;
142 if (write (FileDes(f), (char *)f->buffer, cnt) != cnt)
148 BufFileFlush (BufFilePtr f, int doClose)
150 if (f->bufp != f->buffer)
151 return (*f->output) (BUFFILEEOF, f);
156 BufFileOpenWrite (int fd)
161 /* hv: I'd bet WIN32 has the same effect here */
162 setmode(fd,O_BINARY);
164 f = BufFileCreate ((char *)(long) fd, 0, BufFileRawFlush, 0, BufFileFlush);
166 f->left = BUFFILESIZE;
171 BufFileRead (BufFilePtr f, char *b, int n)
185 BufFileWrite (BufFilePtr f, char *b, int n)
190 if (BufFilePut (*b++, f) == BUFFILEEOF)
197 BufFileClose (BufFilePtr f, int doClose)
200 ret = (*f->close) (f, doClose);