From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KwLVA-0001tn-DD for qemu-devel@nongnu.org; Sat, 01 Nov 2008 14:47:12 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KwLV8-0001tV-TQ for qemu-devel@nongnu.org; Sat, 01 Nov 2008 14:47:12 -0400 Received: from [199.232.76.173] (port=47825 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KwLV8-0001tS-R7 for qemu-devel@nongnu.org; Sat, 01 Nov 2008 14:47:10 -0400 Received: from rv-out-0708.google.com ([209.85.198.245]:50058) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KwLV8-0001iA-7u for qemu-devel@nongnu.org; Sat, 01 Nov 2008 14:47:10 -0400 Received: by rv-out-0708.google.com with SMTP id f25so1653400rvb.22 for ; Sat, 01 Nov 2008 11:47:09 -0700 (PDT) Message-ID: Date: Sat, 1 Nov 2008 19:47:09 +0100 From: "andrzej zaborowski" Subject: Re: [Qemu-devel] [5532] Replace uses of strndup (a GNU extension) with Qemu pstrdup In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 2008/11/1 Blue Swirl : > On 11/1/08, andrzej zaborowski wrote: >> 2008/10/25 Blue Swirl : >> >> > Revision: 5532 >> > http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5532 >> > Author: blueswir1 >> > Date: 2008-10-25 11:23:27 +0000 (Sat, 25 Oct 2008) >> > >> > Log Message: >> > ----------- >> > Replace uses of strndup (a GNU extension) with Qemu pstrdup >> > >> > Modified Paths: >> > -------------- >> > trunk/cutils.c >> > trunk/hw/bt-hci.c >> > trunk/qemu-common.h >> > >> > Modified: trunk/cutils.c >> > =================================================================== >> > --- trunk/cutils.c 2008-10-25 11:21:28 UTC (rev 5531) >> > +++ trunk/cutils.c 2008-10-25 11:23:27 UTC (rev 5532) >> > @@ -50,6 +50,18 @@ >> > return buf; >> > } >> > >> > +/* strdup with a limit */ >> > +char *pstrdup(const char *str, size_t buf_size) >> > +{ >> > + size_t len; >> > + char *buf; >> > + >> > + len = MIN(buf_size, strlen(str)); >> > + buf = qemu_malloc(len); >> > + pstrcpy(buf, len, str); >> > + return buf; >> > +} >> > + >> > int strstart(const char *str, const char *val, const char **ptr) >> > { >> > const char *p, *q; >> > >> > Modified: trunk/hw/bt-hci.c >> > =================================================================== >> > --- trunk/hw/bt-hci.c 2008-10-25 11:21:28 UTC (rev 5531) >> > +++ trunk/hw/bt-hci.c 2008-10-25 11:23:27 UTC (rev 5532) >> > @@ -1814,7 +1814,7 @@ >> > >> > if (hci->device.lmp_name) >> > free((void *) hci->device.lmp_name); >> > - hci->device.lmp_name = strndup(PARAM(change_local_name, name), >> > + hci->device.lmp_name = pstrdup(PARAM(change_local_name, name), >> > sizeof(PARAM(change_local_name, name))); >> > bt_hci_event_complete_status(hci, HCI_SUCCESS); >> > break; >> > >> > Modified: trunk/qemu-common.h >> > =================================================================== >> > --- trunk/qemu-common.h 2008-10-25 11:21:28 UTC (rev 5531) >> > +++ trunk/qemu-common.h 2008-10-25 11:23:27 UTC (rev 5532) >> > @@ -82,6 +82,7 @@ >> > /* cutils.c */ >> > void pstrcpy(char *buf, int buf_size, const char *str); >> > char *pstrcat(char *buf, int buf_size, const char *s); >> > +char *pstrdup(const char *str, size_t buf_size); >> > int strstart(const char *str, const char *val, const char **ptr); >> > int stristart(const char *str, const char *val, const char **ptr); >> > time_t mktimegm(struct tm *tm); >> >> >> I would like to revert this and part of the following commit so I can >> merge the missing interface for bt and have it work. > > Well, strndup is still a GNU extension, so it may not be present in > all systems. What if pstrdup was changed to match strndup, would that > be OK? There's still the strncpy change. My idea was to just add strndup to osdep.c because if the semantics are to match anyway then the rename only adds confusion. Cheers