News for hackers. Stuff that matters.
Re:Tell HN: C Experts Panel – Ask us anything about C by teleonorax on Tuesday April 14, 2020 @09:41AM (#22865799)
What's up with `strlcpy` and `strlcat`? Are they getting standardized?
Re:Tell HN: C Experts Panel – Ask us anything about C by AaronBallman on Tuesday April 14, 2020 @09:51AM (#22865922)
We've been considering proposals to add common POSIX APIs into C, but I don't believe we've seen a proposal for strlcpy or strlcat yet. I recall we agreed to add strdup to C given its wide availability and usage.
Re:Tell HN: C Experts Panel – Ask us anything about C by DougGwyn on Tuesday April 14, 2020 @10:17AM (#22866265)
There are deficiencies in almost all proposals. Two new functions which avoid the problems are supposed to be published in C202x: strcasecmp and strncasecmp, added in header strings.h (note: not string.h).
Re:Tell HN: C Experts Panel – Ask us anything about C by sramsay on Tuesday April 14, 2020 @02:48PM (#22869882)
strdup seems like a perfect example of "standardizing existing practice." And it has never struck me as running against the spirit of C.
Re:Tell HN: C Experts Panel – Ask us anything about C by DougGwyn on Tuesday April 14, 2020 @06:20PM (#22872197)
In fact I proposed strdup on a few occasions, but it wasn't adopted. It seems that they didn't like for standard library functions to use malloc. POSIX.1 specifies strdup.
Re:Tell HN: C Experts Panel – Ask us anything about C by rseacord on Tuesday April 14, 2020 @09:47AM (#22865875)
No one has proposed making these standard. I doubt they would gain much support as they are similar to the Annex K Bounds Checked Interface functions strcpy_s and strcat_s but not quite as good IMHO.
Re:Tell HN: C Experts Panel – Ask us anything about C by rseacord on Tuesday April 14, 2020 @09:49AM (#22865899)
There were a number of recent proposals to adopt various POSIX functions by Martin Sebor into C including:

  N2353 2019/03/17 Sebor, Add strdup and strndup to C2X
  N2352 2019/03/17 Sebor, Add stpcpy, and stpncpy to C2X
  N2351 2019/03/17 Sebor, Add strnlen to C2X
He is lurking on this thread as well. These proposals can all be found in the document log at http://www.open-std.org/jtc1/sc22/wg14/www/wg14_document_log...
Re:Tell HN: C Experts Panel – Ask us anything about C by rseacord on Tuesday April 14, 2020 @09:52AM (#22865937)
The results (from the minutes http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2377.pdf)

6.33 Sebor, Add strnlen to C2X [N 2351] Result: No consensus on putting N2351 into C2X.

6.34 Sebor, Add stpcpy, and stpncpy to C2X [N 2352] Result: No consensus to put N2352 into C2X.

6.35 Sebor, Add strdup and strndup to C2X [N 2353] Result: N2353 be put into C2X. The committee wants a proposal for the wide character versions of any POSIX functions voted in this meeting.

Re:Tell HN: C Experts Panel – Ask us anything about C by rmind on Tuesday April 14, 2020 @09:57AM (#22866006)
There have been some disagreements on strlcpy/strlcat (BSD vs glibc crowd), although by now the debate has died off and these functions are pretty widely used. Also, while here, it would be lovely to have strchrnul() included.
Re:Tell HN: C Experts Panel – Ask us anything about C by loeg on Tuesday April 14, 2020 @12:28PM (#22867923)
glibc still refuses to add the functions because they are not required by a standard.
Re:Tell HN: C Experts Panel – Ask us anything about C by teleonorax on Tuesday April 14, 2020 @09:57AM (#22866003)
> similar to the Annex K Bounds Checked Interface functions strcpy_s and strcat_s but not quite as good IMHO.

Err... I thought Annex K is deprecated and dead? Whereas strl* seem very much alive, some compilers even give a "strcpy/strncpy is unsafe, use strlcpy instead" warning.

Re:Tell HN: C Experts Panel – Ask us anything about C by AaronBallman on Tuesday April 14, 2020 @09:58AM (#22866016)
FWIW, Annex K is not currently deprecated.
Re:Tell HN: C Experts Panel – Ask us anything about C by eqvinox on Tuesday April 14, 2020 @10:01AM (#22866061)
It's not commonly available though, e.g. on Linux/BSD systems...
Re:Tell HN: C Experts Panel – Ask us anything about C by AaronBallman on Tuesday April 14, 2020 @11:12AM (#22866959)
Correct -- it would be nice if the glibc maintainers would reconsider their opinion of supporting the optional Annex K functionality. There is definitely user demand for the feature.
Re:Tell HN: C Experts Panel – Ask us anything about C by eqvinox on Tuesday April 14, 2020 @11:58AM (#22867541)
> rseacord 22 minutes ago [-]

> The C Committee has taken two votes on this, and in each case, the committee has been equally divided. Without a consensus to change the standard, the status quo wins.

The fact that it has only survived on status quo is a pretty crass hint that things aren't well with Annex K.

Re:Tell HN: C Experts Panel – Ask us anything about C by beefhash on Tuesday April 14, 2020 @11:22AM (#22867091)
And every BSD out there. And whatever it is that macOS does. Microsoft looks to be the outlier to me.
Re:Tell HN: C Experts Panel – Ask us anything about C by loeg on Tuesday April 14, 2020 @12:29PM (#22867940)
Microsoft does not even implement Annex K.

> Microsoft Visual Studio implements an early version of the APIs. However, the implementation is incomplete and conforms neither to C11 nor to the original TR 24731-1.

> As a result of the numerous deviations from the specification the Microsoft implementation cannot be considered conforming or portable.

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1967.htm

Re:Tell HN: C Experts Panel – Ask us anything about C by saagarjha on Tuesday April 14, 2020 @08:51PM (#22873247)
macOS is POSIX compliant.
Re:Tell HN: C Experts Panel – Ask us anything about C by loeg on Tuesday April 14, 2020 @12:28PM (#22867930)
It should be.
Re:Tell HN: C Experts Panel – Ask us anything about C by loeg on Tuesday April 14, 2020 @12:27PM (#22867915)
Well, I am informally proposing making those standard :-).

IMO they're a lot more ergonomic than the Annex K functions, and do the thing most programmers think the strncat/strncpy functions do (admittedly, not part of ISO C).

Annex K should be forgotten as the mistake it is and we can move on with existing real-world interfaces instead of inventing features from whole-cloth. I thought that was generally the C standard operating practice.

Re:Tell HN: C Experts Panel – Ask us anything about C by saagarjha on Tuesday April 14, 2020 @08:51PM (#22873242)
I disagree, because they return a value that nobody really wants and thus perform poorly: https://saagarjha.com/blog/2020/04/12/designing-a-better-str...
Re:Tell HN: C Experts Panel – Ask us anything about C by loeg on Wednesday April 15, 2020 @02:03AM (#22875024)
So standardize them as returning void — great!
Re:Tell HN: C Experts Panel – Ask us anything about C by saagarjha on Wednesday April 15, 2020 @05:03AM (#22875816)
What you really want is it to tell you how much it copied.
Re:Tell HN: C Experts Panel – Ask us anything about C by loeg on Wednesday April 15, 2020 @03:11PM (#22881785)
I don't think I've ever wanted to know that, actually. Void is totally fine for my use.
Re:Tell HN: C Experts Panel – Ask us anything about C by saagarjha on Tuesday April 14, 2020 @08:49PM (#22873231)
I hope not, they perform much worse than they need to :(