diff --git a/libs/util/quakefs.c b/libs/util/quakefs.c index a5ec9ff96..c7a7bd728 100644 --- a/libs/util/quakefs.c +++ b/libs/util/quakefs.c @@ -166,65 +166,6 @@ COM_FileOpenRead (char *path, QFile **hndl) return Qfilesize (f); } -QFile * -COM_SafeOpenRead (const char *filename) -{ - QFile *f; - - f = Qopen (filename, "rb"); - - if (!f) - Sys_Error ("Error opening %s: %s", filename, strerror (errno)); - - return f; -} - -QFile * -COM_SafeOpenWrite (const char *filename) -{ - QFile *f; - - f = Qopen (filename, "wb"); - - if (!f) - Sys_Error ("Error opening %s: %s", filename, strerror (errno)); - - return f; -} - -void -COM_SafeRead (QFile *f, void *buffer, int count) -{ - if (Qread (f, buffer, count) != (size_t) count) - Sys_Error ("File read failure"); -} - -void -COM_SafeWrite (QFile *f, const void *buffer, int count) -{ - if (Qwrite (f, buffer, count) != (size_t) count) - Sys_Error ("File read failure"); -} - -int -LoadFile (const char *filename, void **bufferptr) -{ - int length; - void *buffer; - QFile *f; - - f = COM_SafeOpenRead (filename); - length = Qfilesize (f); - buffer = malloc (length + 1); - SYS_CHECKMEM (buffer); - ((char *) buffer)[length] = 0; - COM_SafeRead (f, buffer, length); - Qclose (f); - - *bufferptr = buffer; - return length; -} - void COM_Path_f (void) diff --git a/tools/qfcc/include/cmdlib.h b/tools/qfcc/include/cmdlib.h deleted file mode 100644 index dae8c8d72..000000000 --- a/tools/qfcc/include/cmdlib.h +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (C) 1996-1997 Id Software, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - See file, 'COPYING', for details. - - $Id$ -*/ - -// cmdlib.h - -#ifndef __CMDLIB__ -#define __CMDLIB__ - -#include - -int LoadFile (const char *filename, void **bufferptr); - -#endif diff --git a/tools/qfcc/source/idstuff.c b/tools/qfcc/source/idstuff.c index 99a6dcef0..966f0071f 100644 --- a/tools/qfcc/source/idstuff.c +++ b/tools/qfcc/source/idstuff.c @@ -44,7 +44,6 @@ static const char rcsid[] = #include #include -#include "cmdlib.h" #include "def.h" #include "qfcc.h" #include "expr.h" diff --git a/tools/qfcc/source/qfcc.c b/tools/qfcc/source/qfcc.c index 16d81c87e..cc06a0fa2 100644 --- a/tools/qfcc/source/qfcc.c +++ b/tools/qfcc/source/qfcc.c @@ -66,7 +66,6 @@ static const char rcsid[] = #include "qfcc.h" #include "class.h" -#include "cmdlib.h" #include "cpp.h" #include "debug.h" #include "def.h" @@ -598,6 +597,22 @@ separate_compile (void) return err; } +static const char * +load_file (const char *fname) +{ + QFile *file; + char *src; + + file = Qopen (fname, "rt"); + if (!file) + return 0; + src = malloc (Qfilesize (file) + 1); + src[Qfilesize (file)] = 0; + Qread (file, src, Qfilesize (file)); + Qclose (file); + return src; +} + static int progs_src_compile (void) { @@ -616,7 +631,8 @@ progs_src_compile (void) dsprintf (filename, "%s/%s", sourcedir, progs_src); else dsprintf (filename, "%s", progs_src); - LoadFile (filename->str, (void *) &src); + + src = load_file (filename->str); if (!(src = COM_Parse (src))) { fprintf (stderr, "No destination filename. qfcc --help for info.\n"); diff --git a/tools/qfmodelgen/source/cmdlib.c b/tools/qfmodelgen/source/cmdlib.c index f4d088ef2..313d506bf 100644 --- a/tools/qfmodelgen/source/cmdlib.c +++ b/tools/qfmodelgen/source/cmdlib.c @@ -721,6 +721,26 @@ CreatePath (char *path) } } +int +LoadFile (char *fname, void **buf) +{ + QFile *file; + char *src; + int len; + + *buf = 0; + file = Qopen (fname, "rt"); + if (!file) + return 0; + len = Qfilesize (file); + src = malloc (len + 1); + src[Qfilesize (file)] = 0; + Qread (file, src, len); + Qclose (file); + *buf = src; + return len; +} + /* ============ CopyFile