? alloc-msvc-syntax.patch ? config.h ? findme.patch ? makefile.msc ? parse.patch ? pkg.patch ? popt.patch ? poptconfig.patch ? poptconfig.pathc ? popthelp.patch ? poptparse.patch Index: findme.c =================================================================== RCS file: /cvs/pkgconfig/pkgconfig/findme.c,v retrieving revision 1.4 diff -u -r1.4 findme.c --- findme.c 12 Sep 2002 20:47:07 -0000 1.4 +++ findme.c 7 Jul 2004 00:51:21 -0000 @@ -52,7 +52,8 @@ char * path = getenv("PATH"); char * pathbuf; char * start, * chptr; - char * buf; + char * buf, *free_ptr; + int path_len = strlen( path ); /* If there is a / in the argv[0], it has to be an absolute path */ @@ -61,8 +62,12 @@ if (!path) return NULL; - start = pathbuf = alloca(strlen(path) + 1); - buf = malloc(strlen(path) + strlen(argv0) + 2); +#ifdef HAVE_ALLOCA_H + start = pathbuf = alloca(path_len + 1); +#else + free_ptr = start = pathbuf = g_strdup( path ); +#endif + buf = malloc(path_len + strlen(argv0) + 2); strcpy(pathbuf, path); chptr = NULL; @@ -82,5 +87,7 @@ free(buf); + free( free_ptr ); + return NULL; } Index: parse.c =================================================================== RCS file: /cvs/pkgconfig/pkgconfig/parse.c,v retrieving revision 1.14 diff -u -r1.14 parse.c --- parse.c 1 May 2003 01:14:30 -0000 1.14 +++ parse.c 7 Jul 2004 00:51:22 -0000 @@ -40,6 +40,59 @@ #endif +static +gchar *canonicalize_path( const char *path, int len ) +{ + int i; + gchar *comp; + + if( msvc_syntax ){ // windows style path seperators + comp = (char*)g_malloc( len + 1 ); + for( i = 0; i < len; ++i ) + { + if( path[i] == '/' ){ + comp[i] = '\\'; + } + else + comp[i] = path[i]; + } + comp[i] = '\0'; + } + else{ // unix style path seperators + int offset = 0; + int rlen; + const gchar *start = g_path_skip_root( path ); // requires absolute path + + if( start ){ + rlen = len -= start - path; +#ifdef WIN32 // cygwin style + offset = strlen( "/cygdrive/" )+2; + len += offset + 3; // windows need extra space for the drive letter cygwin style +#endif + + comp = (char*)g_malloc( len + 1 ); +#ifdef WIN32 + strcpy( comp, "/cygdrive/" ); + comp[offset-2] = tolower( path[0] ); // get the drive letter + comp[offset-1] = '/'; +#endif + for( i = 0; i < rlen; ++i ) + { + if( start[i] == '\\' ){ + comp[i+offset] = '/'; + } + else + comp[i+offset] = start[i]; + } + comp[i+offset] = '\0'; + } + else + return g_strndup( path, len ); // risk it + } + return comp; +} + + /** * Read an entire line from a file into a buffer. Lines may * be delimited with '\n', '\r', '\n\r', or '\r\n'. The delimiter @@ -565,8 +618,8 @@ static void parse_conflicts (Package *pkg, const char *str, const char *path) { - GSList *parsed; - GSList *iter; +// GSList *parsed; +// GSList *iter; char *trimmed; if (pkg->conflicts) @@ -581,6 +634,55 @@ g_free (trimmed); } +#ifdef G_OS_WIN32 +/* walk through each directory listed in LIB to determine + * if the library should be prefixed with lib or not + */ +static gboolean +lib_suffix_needed( const char *base_lib_name, const char *lib_suffix ) +{ + const gchar *libpath = g_getenv( "LIB" ); + if( libpath ){ + gchar **lib_paths = g_strsplit( libpath, ";", -1 ); + gchar **path_iter; +// g_print( "processing the LIB environment variable: %s\n", libpath ); + + for( path_iter = lib_paths; *path_iter; ++path_iter ){ + gchar *base = g_strconcat( base_lib_name, lib_suffix, NULL ); + gchar *path = g_build_filename( *path_iter, base, NULL ); + +// g_print( "\tchecking path: %s\n", path ); + + if( g_file_test( path, G_FILE_TEST_EXISTS ) ){ + g_free( path ); + g_free( base ); + return FALSE; + } + g_free( path ); + g_free( base ); + base = g_strconcat( "lib", base_lib_name, lib_suffix, NULL ); + + /* test it with the lib prefix */ + path = g_build_filename( *path_iter, base, NULL ); +// g_print( "\tchecking path: %s\n", path ); + + if( g_file_test( path, G_FILE_TEST_EXISTS ) ){ + g_free( path ); + g_free( base ); + return TRUE; + } + + g_free( path ); + g_free( base ); + + } + + g_strfreev( lib_paths ); + } + return FALSE; +} +#endif + static void parse_libs (Package *pkg, const char *str, const char *path) { @@ -595,10 +697,12 @@ char *L_flag = (msvc_syntax ? "/libpath:" : "-L"); char *l_flag = (msvc_syntax ? "" : "-l"); char *lib_suffix = (msvc_syntax ? ".lib" : ""); + char *lib_prefix = NULL; //(msvc_syntax ? "lib" : ""); #else char *L_flag = "-L"; char *l_flag = "-l"; char *lib_suffix = ""; + char *lib_prefix = NULL; //""; #endif if (pkg->l_libs || pkg->L_libs || pkg->other_libs) @@ -643,10 +747,18 @@ while (*p && !isspace ((guchar)*p)) ++p; - libname = g_strndup (start, p - start); - + libname = canonicalize_path( start, p - start );//g_strndup (start, p - start); +#ifdef G_OS_WIN32 + if( msvc_syntax && lib_suffix_needed( libname, lib_suffix ) ) + lib_prefix = g_strdup( "lib" ); + else + lib_prefix = g_strdup( "" ); +#endif pkg->l_libs = g_slist_prepend (pkg->l_libs, - g_strconcat (l_flag, libname, lib_suffix, NULL)); + g_strconcat (l_flag, lib_prefix, libname, lib_suffix, NULL)); +#ifdef G_OS_WIN32 + g_free( lib_prefix ); +#endif g_free (libname); } @@ -663,7 +775,7 @@ while (*p && !isspace ((guchar)*p)) ++p; - libname = g_strndup (start, p - start); + libname = canonicalize_path( start, p - start );//g_strndup (start, p - start); pkg->L_libs = g_slist_prepend (pkg->L_libs, g_strconcat (L_flag, libname, NULL)); @@ -743,7 +855,7 @@ while (*p && !isspace ((guchar)*p)) ++p; - libname = g_strndup (start, p - start); + libname = canonicalize_path (start, p - start); pkg->I_cflags = g_slist_prepend (pkg->I_cflags, g_strconcat ("-I", libname, NULL)); @@ -768,20 +880,7 @@ pkg->I_cflags = g_slist_reverse (pkg->I_cflags); pkg->other_cflags = g_slist_reverse (pkg->other_cflags); } - -static void -parse_url (Package *pkg, const char *str, const char *path) -{ - if (pkg->url != NULL) - { - verbose_error ("URL field occurs twice in '%s'\n", path); - - exit (1); - } - - pkg->url = trim_and_sub (pkg, str, path); -} - + static void parse_line (Package *pkg, const char *untrimmed, const char *path) { @@ -832,17 +931,12 @@ parse_cflags (pkg, p, path); else if (strcmp (tag, "Conflicts") == 0) parse_conflicts (pkg, p, path); - else if (strcmp (tag, "URL") == 0) - parse_url (pkg, p, path); else { - /* we don't error out on unknown keywords because they may - * represent additions to the .pc file format from future - * versions of pkg-config. We do make a note of them in the - * debug spew though, in order to help catch mistakes in .pc - * files. */ - debug_spew ("Unknown keyword '%s' in '%s'\n", - tag, path); + verbose_error ("Unknown keyword '%s' in '%s'\n", + tag, path); + + exit (1); } } else if (*p == '=') @@ -948,7 +1042,7 @@ if (path) { - pkg->pcfiledir = g_dirname (path); + pkg->pcfiledir = g_path_get_dirname (path); } else { Index: pkg.c =================================================================== RCS file: /cvs/pkgconfig/pkgconfig/pkg.c,v retrieving revision 1.31 diff -u -r1.31 pkg.c --- pkg.c 1 May 2003 01:14:30 -0000 1.31 +++ pkg.c 7 Jul 2004 00:51:22 -0000 @@ -34,7 +34,9 @@ #endif #include + #include + #include #include #include @@ -130,7 +132,7 @@ } dir = opendir (dirname_copy); - free (dirname_copy); + g_free (dirname_copy); if (!dir) { debug_spew ("Cannot open directory '%s' in package search path: %s\n", @@ -183,26 +185,6 @@ } } -static Package * -add_virtual_pkgconfig_package (void) -{ - Package *pkg = NULL; - - pkg = g_new0 (Package, 1); - - pkg->key = g_strdup ("pkg-config"); - pkg->version = g_strdup (VERSION); - pkg->name = g_strdup ("pkg-config"); - pkg->description = g_strdup ("pkg-config is a system for managing " - "compile/link flags for libraries"); - pkg->url = g_strdup ("http://www.freedesktop.org/software/pkgconfig/"); - - debug_spew ("Adding virtual 'pkg-config' package to list of known packages\n"); - g_hash_table_insert (packages, pkg->key, pkg); - - return pkg; -} - void package_init () { @@ -221,8 +203,6 @@ locations = g_hash_table_new (g_str_hash, g_str_equal); path_positions = g_hash_table_new (g_str_hash, g_str_equal); - add_virtual_pkgconfig_package (); - g_slist_foreach (search_dirs, (GFunc)scan_dir, NULL); scan_dir (pkglibdir); } @@ -674,7 +654,9 @@ gchar **values; gint i; - values = g_strsplit (env, G_SEARCHPATH_SEPARATOR_S, 0); + /* FIXME: the separator should be a ';' on Windows + */ + values = g_strsplit (env, ":", 0); for (i = 0; values[i] != NULL; i++) { list = g_slist_append (list, g_strdup (values[i])); @@ -716,14 +698,14 @@ if (pkg->version == NULL) { verbose_error ("Package '%s' has no Version: field\n", - pkg->key); + pkg->name); exit (1); } if (pkg->description == NULL) { verbose_error ("Package '%s' has no Description: field\n", - pkg->key); + pkg->description); exit (1); } @@ -750,9 +732,6 @@ ver->version, req->name, req->version); - if (req->url) - verbose_error ("You may find new versions of %s at %s\n", - req->name, req->url); exit (1); } @@ -807,10 +786,8 @@ /* We make a list of system directories that gcc expects so we can remove * them. */ -#ifndef G_OS_WIN32 system_directories = g_slist_append (NULL, g_strdup ("/usr/include")); -#endif - + c_include_path = g_getenv ("C_INCLUDE_PATH"); if (c_include_path != NULL) { @@ -873,31 +850,25 @@ g_slist_foreach (system_directories, (GFunc) g_free, NULL); g_slist_free (system_directories); -#ifdef PREFER_LIB64 -#define SYSTEM_LIBDIR "/usr/lib64" -#else -#define SYSTEM_LIBDIR "/usr/lib" -#endif count = 0; iter = pkg->L_libs; while (iter != NULL) { - if (strcmp (iter->data, "-L" SYSTEM_LIBDIR) == 0 || - strcmp (iter->data, "-L " SYSTEM_LIBDIR) == 0) + if (strcmp (iter->data, "-L/usr/lib") == 0 || + strcmp (iter->data, "-L /usr/lib") == 0) { - debug_spew ("Package %s has -L" SYSTEM_LIBDIR " in Libs\n", + debug_spew ("Package %s has -L/usr/lib in Libs\n", pkg->name); if (g_getenv ("PKG_CONFIG_ALLOW_SYSTEM_LIBS") == NULL) { iter->data = NULL; ++count; - debug_spew ("Removing -L" SYSTEM_LIBDIR " from libs for %s\n", pkg->key); + debug_spew ("Removing -L/usr/lib from libs for %s\n", pkg->key); } } iter = iter->next; } -#undef SYSTEM_LIBDIR while (count) { @@ -1230,14 +1201,21 @@ char oldch1, oldch2; char * str1, * str2; char * one, * two; + char * pstr1, * pstr2; int rc; int isnum; /* easy comparison to see if versions are identical */ if (!strcmp(a, b)) return 0; - +#ifdef HAVE_ALLOCA_H str1 = alloca(strlen(a) + 1); str2 = alloca(strlen(b) + 1); +#define CLEANUP +#else + pstr1 = str1 = malloc(strlen(a) + 1); + pstr2 = str2 = malloc(strlen(b) + 1); +#define CLEANUP free( pstr1 ); free( pstr2 ); +#endif strcpy(str1, a); strcpy(str2, b); @@ -1275,8 +1253,8 @@ /* take care of the case where the two version segments are */ /* different types: one numeric and one alpha */ - if (one == str1) return -1; /* arbitrary */ - if (two == str2) return -1; + if (one == str1) { CLEANUP return -1; } /* arbitrary */ + if (two == str2) { CLEANUP return -1; } if (isnum) { /* this used to be done by converting the digit segments */ @@ -1288,8 +1266,8 @@ while (*two == '0') two++; /* whichever number has more digits wins */ - if (strlen(one) > strlen(two)) return 1; - if (strlen(two) > strlen(one)) return -1; + if (strlen(one) > strlen(two)) { CLEANUP return 1; } + if (strlen(two) > strlen(one)) { CLEANUP return -1; } } /* strcmp will return which one is greater - even if the two */ @@ -1297,7 +1275,7 @@ /* if they are equal because there might be more segments to */ /* compare */ rc = strcmp(one, two); - if (rc) return rc; + if (rc) { CLEANUP return rc; } /* restore character that was replaced by null above */ *str1 = oldch1; @@ -1309,10 +1287,12 @@ /* this catches the case where all numeric and alpha segments have */ /* compared identically but the segment sepparating characters were */ /* different */ - if ((!*one) && (!*two)) return 0; + if ((!*one) && (!*two)) { CLEANUP return 0; } /* whichever version still has characters left over wins */ - if (!*one) return -1; else return 1; + if (!*one){ CLEANUP return -1; } else { CLEANUP return 1; } + + CLEANUP } int Index: popt.c =================================================================== RCS file: /cvs/pkgconfig/pkgconfig/popt.c,v retrieving revision 1.3 diff -u -r1.3 popt.c --- popt.c 6 Sep 2002 19:32:18 -0000 1.3 +++ popt.c 7 Jul 2004 00:51:22 -0000 @@ -208,7 +208,11 @@ if (!con->execAbsolute && strchr(script, '/')) return; if (!strchr(script, '/') && con->execPath) { +#ifdef HAVE_ALLOCA_H argv[pos] = alloca(strlen(con->execPath) + strlen(script) + 2); +#else + argv[pos] = malloc(strlen(con->execPath) + strlen(script) + 2); +#endif sprintf(argv[pos], "%s/%s", con->execPath, script); } else { argv[pos] = script; @@ -216,7 +220,8 @@ pos++; argv[pos] = findProgramPath(con->os->argv[0]); - if (argv[pos]) pos++; + if (argv[pos]) + pos++; argv[pos++] = ";"; memcpy(argv + pos, con->finalArgv, sizeof(*argv) * con->finalArgvCount); @@ -298,6 +303,7 @@ poptCallbackType cb; void * cbData; int singleDash; + char *free_ptr = 0; while (!done) { while (!con->os->nextCharArg && con->os->next == con->os->argc @@ -323,12 +329,20 @@ } /* Make a copy we can hack at */ +#ifdef HAVE_ALLOCA_H localOptString = optString = strcpy(alloca(strlen(origOptString) + 1), origOptString); +#define ALLOCA_FREE +#else + free_ptr = localOptString = optString = strdup( origOptString ); +#define ALLOCA_FREE if( free_ptr ) free( free_ptr ); +#endif - if (!optString[0]) + if (!optString[0]){ + ALLOCA_FREE return POPT_ERROR_BADOPT; + } if (optString[1] == '-' && !optString[2]) { con->restLeftover = 1; @@ -354,7 +368,10 @@ opt = findOption(con->options, optString, '\0', &cb, &cbData, singleDash); - if (!opt && !singleDash) return POPT_ERROR_BADOPT; + if (!opt && !singleDash){ + ALLOCA_FREE + return POPT_ERROR_BADOPT; + } } if (!opt) @@ -376,7 +393,10 @@ opt = findOption(con->options, NULL, *origOptString, &cb, &cbData, 0); - if (!opt) return POPT_ERROR_BADOPT; + if (!opt){ + ALLOCA_FREE + return POPT_ERROR_BADOPT; + } origOptString++; if (*origOptString) @@ -395,8 +415,10 @@ while (con->os->next == con->os->argc && con->os > con->optionStack) con->os--; - if (con->os->next == con->os->argc) + if (con->os->next == con->os->argc){ + ALLOCA_FREE return POPT_ERROR_NOARG; + } con->os->nextArg = con->os->argv[con->os->next++]; } @@ -410,16 +432,22 @@ case POPT_ARG_INT: case POPT_ARG_LONG: aLong = strtol(con->os->nextArg, &end, 0); - if (*end) + if (*end) { + ALLOCA_FREE return POPT_ERROR_BADNUMBER; + } - if (aLong == LONG_MIN || aLong == LONG_MAX) + if (aLong == LONG_MIN || aLong == LONG_MAX){ + ALLOCA_FREE return POPT_ERROR_OVERFLOW; + } if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_LONG) { *((long *) opt->arg) = aLong; } else { - if (aLong > INT_MAX || aLong < INT_MIN) + if (aLong > INT_MAX || aLong < INT_MIN){ + ALLOCA_FREE return POPT_ERROR_OVERFLOW; + } *((int *) opt->arg) =aLong; } break; @@ -427,6 +455,7 @@ default: fprintf(stdout, POPT_("option type (%d) not implemented in popt\n"), opt->argInfo & POPT_ARG_MASK); + ALLOCA_FREE exit(1); } } @@ -454,6 +483,7 @@ if (opt->arg && (opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE) con->finalArgv[con->finalArgvCount++] = strdup(con->os->nextArg); } + ALLOCA_FREE return opt->val; } Index: poptconfig.c =================================================================== RCS file: /cvs/pkgconfig/pkgconfig/poptconfig.c,v retrieving revision 1.3 diff -u -r1.3 poptconfig.c --- poptconfig.c 22 Feb 2003 04:59:20 -0000 1.3 +++ poptconfig.c 7 Jul 2004 00:51:22 -0000 @@ -1,27 +1,6 @@ -/* -Copyright (c) 1998 Red Hat Software - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the X Consortium shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from the X Consortium. -*/ +/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING + file accompanying popt source distributions, available from + ftp://ftp.redhat.com/pub/code/popt */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -104,6 +83,7 @@ char * buf, * dst; int fd, rc; int fileLength; + char * free_ptr; fd = open(fn, O_RDONLY); if (fd < 0) { @@ -116,16 +96,27 @@ fileLength = lseek(fd, 0, SEEK_END); lseek(fd, 0, 0); +#ifdef HAVE_ALLOCA_H file = alloca(fileLength + 1); +#else + file = malloc( fileLength + 1 ); +#endif if ((fd = read(fd, file, fileLength)) != fileLength) { rc = errno; close(fd); errno = rc; +#ifndef HAVE_ALLOCA_H + free( file ); +#endif return POPT_ERROR_ERRNO; } close(fd); +#ifdef HAVE_ALLOCA_H dst = buf = alloca(fileLength + 1); +#else + free_ptr = dst = buf = malloc(fileLength + 1); +#endif chptr = file; end = (file + fileLength); @@ -154,6 +145,9 @@ *dst++ = *chptr++; } } +#ifndef HAVE_ALLOCA_H + free( free_ptr ); +#endif return 0; } @@ -171,11 +165,19 @@ if (getuid() != geteuid()) return 0; if ((home = getenv("HOME"))) { +#ifdef HAVE_ALLOCA_H fn = alloca(strlen(home) + 20); +#else + fn = malloc(strlen(home) + 20); +#endif strcpy(fn, home); strcat(fn, "/.popt"); rc = poptReadConfigFile(con, fn); - if (rc) return rc; +#ifndef HAVE_ALLOCA_H + free( fn ); +#endif + if (rc) + return rc; } return 0; Index: popthelp.c =================================================================== RCS file: /cvs/pkgconfig/pkgconfig/popthelp.c,v retrieving revision 1.3 diff -u -r1.3 popthelp.c --- popthelp.c 22 Feb 2003 04:59:20 -0000 1.3 +++ popthelp.c 7 Jul 2004 00:51:22 -0000 @@ -1,27 +1,6 @@ -/* -Copyright (c) 1998 Red Hat Software - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the X Consortium shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from the X Consortium. -*/ +/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING + file accompanying popt source distributions, available from + ftp://ftp.redhat.com/pub/code/popt */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -84,8 +63,15 @@ int helpLength; const char * ch; char format[10]; - char * left = alloca(maxLeftCol + 1); + char * left; const char * argDescrip = getArgDescrip(opt); +#ifdef HAVE_ALLOCA_H + left = alloca(maxLeftCol + 1); +#define CLEAN_RETURN return +#else + left = malloc(maxLeftCol + 1); +#define CLEAN_RETURN free( left ); return +#endif *left = '\0'; if (opt->longName && opt->shortName) @@ -94,7 +80,7 @@ sprintf(left, "-%c", opt->shortName); else if (opt->longName) sprintf(left, "--%s", opt->longName); - if (!*left) return ; + if (!*left) CLEAN_RETURN ; if (argDescrip) { strcat(left, "="); strcat(left, argDescrip); @@ -104,7 +90,7 @@ fprintf(f," %-*s ", maxLeftCol, left); else { fprintf(f," %s\n", left); - return; + CLEAN_RETURN; } helpLength = strlen(help); @@ -123,6 +109,8 @@ } if (helpLength) fprintf(f, "%s\n", help); + + CLEAN_RETURN; } static int maxArgWidth(const struct poptOption * opt) { Index: poptparse.c =================================================================== RCS file: /cvs/pkgconfig/pkgconfig/poptparse.c,v retrieving revision 1.2 diff -u -r1.2 poptparse.c --- poptparse.c 22 Feb 2003 04:59:20 -0000 1.2 +++ poptparse.c 7 Jul 2004 00:51:22 -0000 @@ -1,27 +1,6 @@ -/* -Copyright (c) 1998 Red Hat Software - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the X Consortium shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from the X Consortium. -*/ +/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING + file accompanying popt source distributions, available from + ftp://ftp.redhat.com/pub/code/popt */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -41,8 +20,17 @@ #include "popt.h" -int poptParseArgvString(char * s, int * argcPtr, char *** argvPtr) { - char * buf = strcpy(alloca(strlen(s) + 1), s); +int poptParseArgvString(char * s, int * argcPtr, char *** argvPtr) +{ + int s_len = strlen(s); +#ifdef HAVE_ALLOCA_H + char * buf = strcpy(alloca(s_len + 1), s); +#define RETURN_CLEANUP( r_val ) return r_val +#else + char * buf; + char * free_ptr = buf = strdup( s ); +#define RETURN_CLEANUP( r_val ) free( free_ptr ); return r_val +#endif char * bufStart = buf; char * src, * dst; char quote = '\0'; @@ -56,19 +44,20 @@ dst = buf; argv[argc] = buf; - memset(buf, '\0', strlen(s) + 1); + memset(buf, '\0', s_len + 1); while (*src) { if (quote == *src) { quote = '\0'; } else if (quote) { if (*src == '\\') { - src++; + ++src; if (!*src) { free(argv); - return POPT_ERROR_BADQUOTE; + RETURN_CLEANUP( POPT_ERROR_BADQUOTE ); } - if (*src != quote) *buf++ = '\\'; + if (*src != quote) + *buf++ = '\\'; } *buf++ = *src; } else if (isspace(*src)) { @@ -89,7 +78,7 @@ src++; if (!*src) { free(argv); - return POPT_ERROR_BADQUOTE; + RETURN_CLEANUP( POPT_ERROR_BADQUOTE ); } /* fallthrough */ default: @@ -118,5 +107,6 @@ *argvPtr = argv2; *argcPtr = argc; - return 0; + + RETURN_CLEANUP( 0 ); }