upload tizen2.0 source
[framework/uifw/xorg/lib/libxfont.git] / src / fontfile / fileio.c
1 /*
2
3 Copyright 1991, 1998  The Open Group
4
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
9 documentation.
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
24
25 */
26
27 /*
28  * Author:  Keith Packard, MIT X Consortium
29  */
30
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
34 #include <X11/fonts/fntfilio.h>
35 #include <X11/Xos.h>
36 #ifndef O_BINARY
37 #define O_BINARY O_RDONLY
38 #endif
39
40 FontFilePtr
41 FontFileOpen (const char *name)
42 {
43     int         fd;
44     int         len;
45     BufFilePtr  raw, cooked;
46
47     fd = open (name, O_BINARY);
48     if (fd < 0)
49         return 0;
50     raw = BufFileOpenRead (fd);
51     if (!raw)
52     {
53         close (fd);
54         return 0;
55     }
56     len = strlen (name);
57     if (len > 2 && !strcmp (name + len - 2, ".Z")) {
58         cooked = BufFilePushCompressed (raw);
59         if (!cooked) {
60             BufFileClose (raw, TRUE);
61             return 0;
62         }
63         raw = cooked;
64 #ifdef X_GZIP_FONT_COMPRESSION
65     } else if (len > 3 && !strcmp (name + len - 3, ".gz")) {
66         cooked = BufFilePushZIP (raw);
67         if (!cooked) {
68             BufFileClose (raw, TRUE);
69             return 0;
70         }
71         raw = cooked;
72 #endif
73 #ifdef X_BZIP2_FONT_COMPRESSION
74     } else if (len > 4 && !strcmp (name + len - 4, ".bz2")) {
75         cooked = BufFilePushBZIP2 (raw);
76         if (!cooked) {
77             BufFileClose (raw, TRUE);
78             return 0;
79         }
80         raw = cooked;
81 #endif
82     }
83     return (FontFilePtr) raw;
84 }
85
86 int
87 FontFileClose (FontFilePtr f)
88 {
89     return BufFileClose ((BufFilePtr) f, TRUE);
90 }
91