From 1d7baffb338d8571d9ba15f1ebac67325bb8e94a Mon Sep 17 00:00:00 2001 From: ewt Date: Wed, 4 Mar 1998 16:51:38 +0000 Subject: [PATCH] 1) make use of new delpendency scheme 2) made " #if" look like "# if" for portability 3) added strdup.c CVS patchset: 2021 CVS date: 1998/03/04 16:51:38 --- misc/Makefile.in | 11 +++++------ misc/getmntent.c | 6 +++--- misc/miscfn.h | 28 +++++++++++++++++++++------- misc/strdup.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 16 deletions(-) create mode 100644 misc/strdup.c diff --git a/misc/Makefile.in b/misc/Makefile.in index 35ac3bb..d7365bb 100644 --- a/misc/Makefile.in +++ b/misc/Makefile.in @@ -1,4 +1,5 @@ srcdir = @srcdir@ +top_srcdir = @top_srcdir@ VPATH = $(srcdir) include ../Makefile.inc @@ -8,11 +9,7 @@ LIBMISC = libmisc.a # ----------------------------------------------------------------------- -ifeq (.depend,$(wildcard .depend)) TARGET=everything -else -TARGET=depend everything -endif all: $(TARGET) @@ -28,10 +25,12 @@ clean: rm -f *.a *.o *~ $(PROGS) distclean: clean - rm -f .depend Makefile + rm -f Makefile depend: - $(CPP) $(CFLAGS) -M $(srcdir)/*.c > .depend + topdir_path=`( cd $(top_srcdir) && pwd )` ; \ + $(CPP) $(CFLAGS) -MM $(srcdir)/*.c | \ + sed s+$$topdir_path+$(top_srcdir)+g > .depend ifeq (.depend,$(wildcard .depend)) include .depend diff --git a/misc/getmntent.c b/misc/getmntent.c index 6b0092e..4c0a400 100644 --- a/misc/getmntent.c +++ b/misc/getmntent.c @@ -40,7 +40,7 @@ our_mntent *getmntent(FILE *filep) { if (*chptr == COMMENTCHAR) continue; - #if __aix__ +# if __aix__ /* aix uses a screwed up file format */ if (*chptr == '/') { start = chptr; @@ -49,7 +49,7 @@ our_mntent *getmntent(FILE *filep) { item.mnt_dir = strdup(start); return &item; } - #else +# else while (!isspace(*chptr) && (*chptr)) chptr++; if (!*chptr) return NULL; @@ -62,7 +62,7 @@ our_mntent *getmntent(FILE *filep) { item.our_mntdir = strdup(start); return &item; - #endif +# endif } return NULL; diff --git a/misc/miscfn.h b/misc/miscfn.h index 8b21c68..f7fb1fc 100644 --- a/misc/miscfn.h +++ b/misc/miscfn.h @@ -35,13 +35,19 @@ char *realpath(const char *path, char resolved_path []); #endif +#if HAVE_SYS_STDTYPES_H +# include +#endif + +#if HAVE_SYS_TYPES_H +# include +#endif + #if NEED_TIMEZONE -#include extern time_t timezone; #endif #if NEED_MYREALLOC -#include #define realloc(ptr,size) myrealloc(ptr,size) extern void *myrealloc(void *, size_t); #endif @@ -66,7 +72,15 @@ extern void *myrealloc(void *, size_t); #if HAVE_GETMNTINFO_R || HAVE_MNTCTL # define GETMNTENT_ONE 0 # define GETMNTENT_TWO 0 -# include +# if HAVE_SYS_MNTCTL_H +# include +# endif +# if HAVE_SYS_VMOUNT_H +# include +# endif +# if HAVE_SYS_MOUNT_H +# include +# endif #elif HAVE_MNTENT_H || !(HAVE_GETMNTENT) || HAVE_STRUCT_MNTTAB # if HAVE_MNTENT_H # include @@ -74,15 +88,15 @@ extern void *myrealloc(void *, size_t); # define our_mntent struct mntent # define our_mntdir mnt_dir # elif HAVE_STRUCT_MNTTAB - #include - #include +# include +# include struct our_mntent { char * our_mntdir; }; struct our_mntent *getmntent(FILE *filep); # define our_mntent struct our_mntent # else - #include +# include struct our_mntent { char * our_mntdir; }; @@ -98,7 +112,7 @@ extern void *myrealloc(void *, size_t); # define GETMNTENT_TWO 1 # define our_mntent struct mnttab # define our_mntdir mnt_mountp -#else if !HAVE_MNTCTL +#else /* if !HAVE_MNTCTL */ # error Neither mntent.h, mnttab.h, or mntctl() exists. I cannot build on this system. #endif diff --git a/misc/strdup.c b/misc/strdup.c new file mode 100644 index 0000000..9236fe7 --- /dev/null +++ b/misc/strdup.c @@ -0,0 +1,44 @@ +/* + * Author: Tim Mooney + * Copyright: This file is in the public domain. + * + * a replacement for strdup() for those platforms that don't have it, + * like Ultrix. + * + * Requires: malloc(), strlen(), strcpy(). + * + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#ifdef HAVE_SYS_TYPES_H +# include +#endif + +#if defined(HAVE_STDLIB_H) || defined(STDC_HEADERS) +# include +#else +extern void *malloc(size_t); +#endif + +#if defined(HAVE_STRING_H) || defined(STDC_HEADERS) +# include +#else +extern size_t strlen(const char *); +extern char *strcpy(char *, const char *); +#endif + +char * strdup(const char *s) { + void *p = NULL; + + p = malloc(strlen(s)+1); + if (!p) { + return NULL; + } + + strcpy( (char *) p, s); + return (char *) p; +} + -- 2.7.4