From mboxrd@z Thu Jan 1 00:00:00 1970 From: "John David Anglin" To: aoliva@redhat.com (Alexandre Oliva) Cc: gcc-bugs@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: PATCH: Re: jartool.c:539: undefined reference to `strdup' Date: Thu, 03 May 2001 11:26:00 -0000 Message-id: <200105031826.OAA04587@hiauly1.hia.nrc.ca> References: X-SW-Source: 2001-05/msg00188.html > I don't think so. strdup() is sometimes defined as a macro, and > sometimes it's declared to take a const char *. Better check for it > and define it only if it's not present, or go for libiberty, which I > think would be a better idea. Here is a revised patch. Guaranteed to build and run under vax-dec-ultrix4.3. As I see it, using strdup from libiberty is something to be avoided because there is no declaration for it in libiberty.h. Gcc doesn't use it. It uses xstrdup. However, it has a somewhat different behavior if malloc fails (admittedly unlikely in this case). If you want to link against libiberty, probably jartool.c should include libiberty.h and use xstrdup. Dave -- J. David Anglin dave.anglin@nrc.ca National Research Council of Canada (613) 990-0752 (FAX: 952-6605) 2001-05-03 John David Anglin * jartool.c (jt_strdup): New function. (get_next_arg): Use jt_strdup instead of strdup. --- jartool.c.orig Thu Dec 28 16:47:37 2000 +++ jartool.c Thu May 3 13:41:22 2001 @@ -223,6 +223,7 @@ int make_manifest(int, const char*); static void init_args(char **, int); static char *get_next_arg (void); +static char *jt_strdup (char*); /* global variables */ ub1 file_header[30]; @@ -536,7 +537,7 @@ if (pos) { s [pos] = '\0'; - return strdup (s); + return jt_strdup (s); } else return NULL; @@ -1825,4 +1826,15 @@ "); exit(1); +} + +static char * +jt_strdup(s) + char *s; +{ + char *result = (char*)malloc(strlen(s) + 1); + if (result == (char*)0) + return (char*)0; + strcpy(result, s); + return result; }