]> git.sesse.net Git - rdpsrv/blob - Xserver/lib/font/fontfile/fileio.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / lib / font / fontfile / fileio.c
1 /* $XConsortium: fileio.c /main/5 1996/11/03 19:32:03 kaleb $ */
2 /* $XFree86: xc/lib/font/fontfile/fileio.c,v 3.1 1996/12/23 06:02:20 dawes Exp $ */
3
4 /*
5
6 Copyright (c) 1991  X Consortium
7
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
21 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25 Except as contained in this notice, the name of the X Consortium shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings
27 in this Software without prior written authorization from the X Consortium.
28
29 */
30
31 /*
32  * Author:  Keith Packard, MIT X Consortium
33  */
34
35 #include <fntfilio.h>
36 #include <X11/Xos.h>
37 #ifndef O_BINARY
38 #define O_BINARY 0
39 #endif
40
41 FontFilePtr
42 FontFileOpen (name)
43     char    *name;
44 {
45     int         fd;
46     int         len;
47     BufFilePtr  raw, cooked;
48
49     fd = open (name, O_BINARY);
50     if (fd < 0)
51         return 0;
52     raw = BufFileOpenRead (fd);
53     if (!raw)
54     {
55         close (fd);
56         return 0;
57     }
58     len = strlen (name);
59 #ifndef __EMX__
60     if (len > 2 && !strcmp (name + len - 2, ".Z")) {
61 #else
62     if (len > 2 && (!strcmp (name + len - 4, ".pcz") || 
63                     !strcmp (name + len - 2, ".Z"))) {
64 #endif
65         cooked = BufFilePushCompressed (raw);
66         if (!cooked) {
67             BufFileClose (raw, TRUE);
68             return 0;
69         }
70         raw = cooked;
71 #ifdef X_GZIP_FONT_COMPRESSION
72     } else if (len > 3 && !strcmp (name + len - 3, ".gz")) {
73         cooked = BufFilePushZIP (raw);
74         if (!cooked) {
75             BufFileClose (raw, TRUE);
76             return 0;
77         }
78         raw = cooked;
79 #endif
80     }
81     return (FontFilePtr) raw;
82 }
83
84 FontFileClose (f)
85     FontFilePtr f;
86 {
87     BufFileClose ((BufFilePtr) f, TRUE);
88 }
89