From 25bc35fbadebbf28eed3c89978e435d2df557b42 Mon Sep 17 00:00:00 2001 From: Ian C Date: Tue, 6 Jan 2004 02:06:37 +0000 Subject: Devel checkin - added util and snap objects and non-working TAP support --- src/util.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 src/util.c (limited to 'src/util.c') diff --git a/src/util.c b/src/util.c new file mode 100644 index 0000000..c3396eb --- /dev/null +++ b/src/util.c @@ -0,0 +1,100 @@ +/* + + espec - Sinclair Spectrum emulator + + Copyright (C) 2003 Ian Cowburn (ianc@noddybox.demon.co.uk) + + 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 + + ------------------------------------------------------------------------- + + Usual library wrappers and utils + +*/ +static const char ident[]="$Id$"; + +#include +#include + +#include "util.h" +#include "exit.h" + +static const char ident_h[]=ESPEC_UTIL_H; + + +/* ---------------------------------------- MACROS +*/ +#define DIRSEP '/' + +/* ---------------------------------------- INTERFACES +*/ +void *Malloc(size_t size) +{ + void *p=malloc(size); + + if (!p) + Exit("malloc failed for %lu bytes\n",(unsigned long)size); + + return p; +} + + +char *StrCopy(const char *source) +{ + return strcpy(Malloc(strlen(source)+1),source); +} + + +const char *Basename(const char *path) +{ + const char *p=path+strlen(path); + + while(p>path && *p!=DIRSEP) + p--; + + if (p>path) + p++; + + return p; +} + + +const char *Dirname(const char *path) +{ + static char dir[FILENAME_MAX]; + char *p; + + strcpy(dir,path); + + p=dir+strlen(dir); + + while(p>dir && *p!=DIRSEP) + p--; + + if (p>path) + { + p++; + *p=0; + } + else + { + strcpy(dir,"."); + } + + return dir; +} + + +/* END OF FILE */ -- cgit v1.2.3