fileio.c revision 7f7f5e4e
123a0898aSmrg/* $Xorg: fileio.c,v 1.4 2001/02/09 02:04:03 xorgcvs Exp $ */ 223a0898aSmrg 323a0898aSmrg/* 423a0898aSmrg 523a0898aSmrgCopyright 1991, 1998 The Open Group 623a0898aSmrg 723a0898aSmrgPermission to use, copy, modify, distribute, and sell this software and its 823a0898aSmrgdocumentation for any purpose is hereby granted without fee, provided that 923a0898aSmrgthe above copyright notice appear in all copies and that both that 1023a0898aSmrgcopyright notice and this permission notice appear in supporting 1123a0898aSmrgdocumentation. 1223a0898aSmrg 1323a0898aSmrgThe above copyright notice and this permission notice shall be included in 1423a0898aSmrgall copies or substantial portions of the Software. 1523a0898aSmrg 1623a0898aSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1723a0898aSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1823a0898aSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1923a0898aSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 2023a0898aSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 2123a0898aSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2223a0898aSmrg 2323a0898aSmrgExcept as contained in this notice, the name of The Open Group shall not be 2423a0898aSmrgused in advertising or otherwise to promote the sale, use or other dealings 2523a0898aSmrgin this Software without prior written authorization from The Open Group. 2623a0898aSmrg 2723a0898aSmrg*/ 2823a0898aSmrg/* $XFree86: xc/lib/font/fontfile/fileio.c,v 3.9 2001/12/14 19:56:51 dawes Exp $ */ 2923a0898aSmrg 3023a0898aSmrg/* 3123a0898aSmrg * Author: Keith Packard, MIT X Consortium 3223a0898aSmrg */ 3323a0898aSmrg 3423a0898aSmrg#ifdef HAVE_CONFIG_H 3523a0898aSmrg#include <config.h> 3623a0898aSmrg#endif 3723a0898aSmrg#include <X11/fonts/fntfilio.h> 3823a0898aSmrg#include <X11/Xos.h> 3923a0898aSmrg#ifndef O_BINARY 4023a0898aSmrg#define O_BINARY O_RDONLY 4123a0898aSmrg#endif 4223a0898aSmrg 4323a0898aSmrgFontFilePtr 4423a0898aSmrgFontFileOpen (const char *name) 4523a0898aSmrg{ 4623a0898aSmrg int fd; 4723a0898aSmrg int len; 4823a0898aSmrg BufFilePtr raw, cooked; 4923a0898aSmrg 5023a0898aSmrg fd = open (name, O_BINARY); 5123a0898aSmrg if (fd < 0) 5223a0898aSmrg return 0; 5323a0898aSmrg raw = BufFileOpenRead (fd); 5423a0898aSmrg if (!raw) 5523a0898aSmrg { 5623a0898aSmrg close (fd); 5723a0898aSmrg return 0; 5823a0898aSmrg } 5923a0898aSmrg len = strlen (name); 6023a0898aSmrg if (len > 2 && !strcmp (name + len - 2, ".Z")) { 6123a0898aSmrg cooked = BufFilePushCompressed (raw); 6223a0898aSmrg if (!cooked) { 6323a0898aSmrg BufFileClose (raw, TRUE); 6423a0898aSmrg return 0; 6523a0898aSmrg } 6623a0898aSmrg raw = cooked; 6723a0898aSmrg#ifdef X_GZIP_FONT_COMPRESSION 6823a0898aSmrg } else if (len > 3 && !strcmp (name + len - 3, ".gz")) { 6923a0898aSmrg cooked = BufFilePushZIP (raw); 7023a0898aSmrg if (!cooked) { 7123a0898aSmrg BufFileClose (raw, TRUE); 7223a0898aSmrg return 0; 7323a0898aSmrg } 7423a0898aSmrg raw = cooked; 757f7f5e4eSmrg#endif 767f7f5e4eSmrg#ifdef X_BZIP2_FONT_COMPRESSION 777f7f5e4eSmrg } else if (len > 4 && !strcmp (name + len - 4, ".bz2")) { 787f7f5e4eSmrg cooked = BufFilePushBZIP2 (raw); 797f7f5e4eSmrg if (!cooked) { 807f7f5e4eSmrg BufFileClose (raw, TRUE); 817f7f5e4eSmrg return 0; 827f7f5e4eSmrg } 837f7f5e4eSmrg raw = cooked; 8423a0898aSmrg#endif 8523a0898aSmrg } 8623a0898aSmrg return (FontFilePtr) raw; 8723a0898aSmrg} 8823a0898aSmrg 8923a0898aSmrgint 9023a0898aSmrgFontFileClose (FontFilePtr f) 9123a0898aSmrg{ 9223a0898aSmrg return BufFileClose ((BufFilePtr) f, TRUE); 9323a0898aSmrg} 9423a0898aSmrg 95