Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connectionsPath: ...!2.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Richard Harnden
Newsgroups: comp.lang.c
Subject: Re: avoiding strdup()
Date: Sun, 10 Mar 2024 19:20:00 +0000
Organization: A noiseless patient Spider
Lines: 33
Message-ID:
References:
<87y1ayj6hs.fsf_-_@bsb.me.uk>
<87r0gizzuo.fsf@nosuchdomain.example.com> <20240310101101.00001fd4@yahoo.com>
<20240310100715.866@kylheku.com>
Reply-To: nospam.harnden@invalid.com
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 10 Mar 2024 19:20:00 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="08377d5e8277558f85a2b54dd370257a";
logging-data="3284447"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX194F0kBGwwdjKrkO1smnwUivefSJQIOJmw="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:V6UKvdQmjDSuF0TNYsFoDXakkzk=
Content-Language: en-GB
In-Reply-To:
Bytes: 2679
On 10/03/2024 18:47, Scott Lurndal wrote:
> Kaz Kylheku <433-929-6894@kylheku.com> writes:
>> On 2024-03-10, Michael S wrote:
>>> On Sat, 09 Mar 2024 16:37:19 -0800
>>> Keith Thompson wrote:
>>>> strdup() and strndup() are being added to the C23 standard.
>>>>
>>>
>>> What is justification?
>>
>> strdup is required by POSIX already and thus widely implemented.
>> Many programmers who are not into standards already assume it's in C.
>>
>> For decades, portable programs have been doing things like this:
>>
>> #if HAVE_STRDUP
>> #define xstrdup(s) strdup(s)
>> #else
>> char *xstrdup(const char *); // own definition
>> #endif
>>
>>> What strdup() can do better, for any chosen value of better, than
>>> strlen()+malloc()+memcpy() ?
>>
>> Not take up space in every application for a common library routine.
>
> It's a form of lazy programming. I've seen a lot of open source
> code that uses strdup without checking for failure and frequently
> "forgetting" to free the result.
The hidden use of malloc was one of the reasons it was left out of the
standard library.