From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jakub Jelinek To: Andrew Cagney Cc: Ian Lance Taylor , Thiemo Seufer , binutils@sources.redhat.com Subject: Re: [PATCH] Include alloca.h for bfd Date: Thu, 23 Aug 2001 11:49:00 -0000 Message-id: <20010823205212.J5765@sunsite.ms.mff.cuni.cz> References: <20010821210909.E30301@rembrandt.csv.ica.uni-stuttgart.de> <20010821234604.J30301@rembrandt.csv.ica.uni-stuttgart.de> <20010823174716.E3542@rembrandt.csv.ica.uni-stuttgart.de> <20010823180440.F5765@sunsite.ms.mff.cuni.cz> <20010823181513.F3542@rembrandt.csv.ica.uni-stuttgart.de> <3B8539CD.5060306@cygnus.com> <3B854EA7.7020706@cygnus.com> X-SW-Source: 2001-08/msg00548.html On Thu, Aug 23, 2001 at 02:42:47PM -0400, Andrew Cagney wrote: > > Hmm, shame you can't use asprintf(). It does everything you want > >> except use bfd_malloc(). > > > > > > Now that you mention it, we could use asprintf there. There is an > > implementation in libiberty. If it can't allocate memory, it sets the > > buffer to NULL. > > > > Doesn't matter much, though. > > Yes. Its the bit where bfd_malloc() sets the error message that is missing. Guess size_t len = strlen (h->root.string); char *buf = (char *) bfd_malloc (len + sizeof ("__imp_")); memcpy (buf, "__imp_", sizeof ("__imp_") - 1); memcpy (buf + sizeof ("__imp_") - 1, h->root.string, len + 1); arh = archive_hash_lookup (&arsym_hash, buf, false, false); free(buf); will be faster anyway, so there is no need to look for asprintf for concat of 2 strings together (well, the above would be even nicer with mempcpy). Jakub