From 87f6f0673bc26f705d757758a57b7571db9e803f Mon Sep 17 00:00:00 2001 From: pnenzi Date: Mon, 16 Apr 2001 09:58:25 +0000 Subject: [PATCH] Applied Dan patches for Solaris. Asprintf is masked by HAVE_ASPRINTF. The check is done by autoconf. getopt path not yet applied. --- configure.in | 7 ++++++- src/main.c | 14 ++++++++++++++ src/misc/ivars.c | 26 ++++++++++++++++++++++++++ src/spicelib/parser/ifnewuid.c | 24 ++++++++++++++++++++++++ src/spicelib/parser/inperror.c | 22 +++++++++++++++++++++- 5 files changed, 91 insertions(+), 2 deletions(-) diff --git a/configure.in b/configure.in index 2990c101c..eda07af12 100644 --- a/configure.in +++ b/configure.in @@ -165,9 +165,14 @@ AC_CHECK_HEADERS(float.h limits.h values.h) dnl Check for a few mathematical functions: AC_CHECK_FUNCS(erfc logb scalb scalbn asinh acosh atanh) - +AC_MSG_RESULT(Checking for the presence of the Garbage Collector:) +dnl Check for the garbage collector: AC_CHECK_LIB(gc,GC_malloc,AC_DEFINE(HAVE_LIBGC) LIBS="$LIBS -lgc") +AC_MSG_RESULT(Checking for the asprintf function:) +dnl Check for the asprintf function: +AC_CHECK_FUNCS(asprintf) + # Expand the prefix variable (this is really annoying!) if eval "test x$prefix = xNONE"; then diff --git a/src/main.c b/src/main.c index 205c192a5..be45d5d52 100644 --- a/src/main.c +++ b/src/main.c @@ -8,6 +8,9 @@ #include #include +#ifdef HAVE_STRING_H +#include +#endif /* HAVE_STRING_H */ #include #include @@ -500,7 +503,18 @@ main(int argc, char **argv) struct passwd *pw; pw = getpwuid(getuid()); + +#ifdef HAVE_ASPRINTF asprintf(&s, "%s/.spiceinit", pw->pw_dir); +#else /* ~ HAVE_ASPRINTF */ +#define INITSTR "/.spiceinit" +if ( (s=(char *) malloc(1 + strlen(pw->pw_dir)+strlen(INITSTR))) == NULL){ + fprintf(stderr,"malloc failed\n"); + exit(1); + } + sprintf(s,"%s%s",pw->pw_dir,INITSTR); +#endif /* HAVE_ASPRINTF */ + if (access(s, 0) == 0) inp_source(s); } diff --git a/src/misc/ivars.c b/src/misc/ivars.c index b63a007d8..3fffd630b 100644 --- a/src/misc/ivars.c +++ b/src/misc/ivars.c @@ -4,6 +4,11 @@ Copyright 1991 Regents of the University of California. All rights reserved. #include "ngspice.h" #include "ivars.h" + +#ifdef HAVE_STRING_H +#include +#endif /* HAVE_STRING_H */ + #include #include @@ -29,10 +34,31 @@ mkvar(char **p, char *path_prefix, char *var_dir, char *env_var) /* Override by environment variables */ buffer = getenv(env_var); + +#ifdef HAVE_ASPRINTF if (buffer) asprintf(p, "%s", buffer); else asprintf(p, "%s%s%s", path_prefix, DIR_PATHSEP, var_dir); +#else /* ~ HAVE_ASPRINTF */ + if (buffer){ + if ( (*p = (char *) malloc(strlen(buffer)+1)) == NULL){ + fprintf(stderr,"malloc failed\n"); + exit(1); + } + sprintf(*p,"%s",buffer); + /* asprintf(p, "%s", buffer); */ + } + else{ + if ( (*p = (char *) malloc(strlen(path_prefix) + + strlen(DIR_PATHSEP) + strlen(var_dir) + 1)) == NULL){ + fprintf(stderr,"malloc failed\n"); + exit(1); + } + sprintf(*p, "%s%s%s", path_prefix, DIR_PATHSEP, var_dir); + /* asprintf(p, "%s%s%s", path_prefix, DIR_PATHSEP, var_dir); */ + } +#endif /* HAVE_ASPRINTF */ } void diff --git a/src/spicelib/parser/ifnewuid.c b/src/spicelib/parser/ifnewuid.c index da9000dc7..6e4a4aae5 100644 --- a/src/spicelib/parser/ifnewuid.c +++ b/src/spicelib/parser/ifnewuid.c @@ -6,6 +6,10 @@ Author: 1988 Thomas L. Quarles #include "ngspice.h" #include +#ifdef HAVE_STRING_H +#include +#endif + #include #include #include @@ -26,9 +30,29 @@ IFnewUid(void *ckt, IFuid * newuid, IFuid olduid, char *suffix, int type, int error; if (olduid) { +#ifdef HAVE_ASPRINTF asprintf(&newname, "%s#%s", (char *) olduid, suffix); +#else /* ~ HAVE_ASPRINTF */ + if ( (newname = (char *) malloc(strlen((char *) olduid) + + strlen(suffix) + strlen("#\0"))) + == NULL){ + fprintf(stderr,"malloc failed\n"); + exit(1); + } + sprintf(newname, "%s#%s", (char *) olduid, suffix); +#endif /* HAVE_ASPRINTF */ + } else { + +#ifdef HAVE_ASPRINTF asprintf(&newname, "%s", suffix); +#else /* ~ HAVE_ASPRINTF */ + if ( (newname = (char *) malloc(strlen(suffix) + 1 )) == NULL){ + fprintf(stderr,"malloc failed\n"); + exit(1); + } + sprintf(newname, "%s", suffix); +#endif /* HAVE_ASPRINTF */ } switch (type) { diff --git a/src/spicelib/parser/inperror.c b/src/spicelib/parser/inperror.c index 7cfca2957..9d77710eb 100644 --- a/src/spicelib/parser/inperror.c +++ b/src/spicelib/parser/inperror.c @@ -9,6 +9,9 @@ Author: 1985 Thomas L. Quarles #include "ngspice.h" #include +#ifdef HAVE_STRING_H +#include +#endif #include "fteext.h" #include "ifsim.h" #include "iferrmsg.h" @@ -25,10 +28,27 @@ char *INPerror(int type) if (!val) return (val); +#ifdef HAVE_ASPRINTF if (errRtn) asprintf(&ebuf, "%s detected in routine \"%s\"\n", val, errRtn); else asprintf(&ebuf, "%s\n", val); - +#else /* ~ HAVE_ASPRINTF */ + if (errRtn){ + if ( (ebuf = (char *) malloc(strlen(val) + + strlen(errRtn) + 25)) == NULL){ + fprintf(stderr,"malloc failed\n"); + exit(1); + } + sprintf(ebuf, "%s detected in routine \"%s\"\n", val, errRtn); + } + else{ + if ( (ebuf = (char *) malloc(strlen(val) + 2)) == NULL){ + fprintf(stderr,"malloc failed\n"); + exit(1); + } + sprintf(ebuf, "%s\n", val); + } +#endif /* HAVE_ASPRINTF */ return ebuf; }