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