Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

It's 2015 and Linus still doesn't know what a C string is

Name: Anonymous 2015-05-09 1:49

Name: Anonymous 2015-05-09 2:45

this is crazy but i think it might be you who doesn't know, not linus..

Name: Anonymous 2015-05-09 3:51

good to know that after 40 years C programmers still need to wait linear time to find out how long their strings are

Name: Cudder !cXCudderUE 2015-05-09 4:18

If you need to copy fixed-length strings that should really be bounded only by available memory, you're doing it wrong.

>>3
It's the C standard library that sucks. You can use length-delimited whenever you can.

Name: Anonymous 2015-05-09 9:35

He is right, strlcpy is enterprise poop. Ulrich Drepper was right all along, he should have just been using memcpy instead.

Name: Anonymous 2015-05-09 23:33

>>5
Ulrich is an asshole, but I do think he was right here as well. Security minded developers should be pushing mempcpy, not strlcat.

Name: Anonymous 2015-05-10 12:00

>>4
http://bstring.sourceforge.net/
The Better String Library is an abstraction of a string data type which is superior to the C library char buffer string type, or C++'s std::string.
DON'T FUCKING WHO ARE YOU QUOTING ME

Name: Anonymous 2015-05-10 13:27

>>7
Whom are you quoting?

Name: Anonymous 2015-05-10 13:40

>>8
Your mom.

Name: Anonymous 2015-05-10 15:05

>>7
DON'T FUCKING WHO ARE YOU QUOTING ME
You know you're provoking the sage downvote retard, why do it then?

Name: Anonymous 2015-05-10 15:27

>>10
To provoke him, duh.

Name: Anonymous 2015-05-10 15:49

>>10
Whoever said that saging has anything to with downboating?

Name: Anonymous 2015-05-10 16:14

>>12
Only an outcast from the imageboards would sage-downvote threads on /lounge/ and be annoyed when we call him out on his abuse of quotes. There is only one retard like that and that's him.

Name: Anonymous 2015-05-10 16:25

If it ain't LISP it's shit.

Name: Anonymous 2015-05-10 18:17

>>13
I repeat: who ever said that saging has anything to with downboating? When I sage, I just sage, without any "downvoting" or "karma decrement".

Name: Anonymous 2015-05-10 19:40

So what's the New Improved Method to replace strlcpy(buffer, "the default value", size_of_buffer);, then? Surely nothing that involves typing the string literal twice.

That being said, there are circumstances where mempcpy() etc. would be just the bee's knees. strlcpy() isn't one. strlcat(), though, is.

Name: Anonymous 2015-05-10 21:27

>>16
The problem with strlcpy and friends is they silently truncate the destination string to fit in the provided length. There are many cases where this behavior is not acceptable, and it is often quite trivial to avoid the possibility altogether. In your example, if the caller controls the allocation of buffer there should be no cause to use strlcpy at all - it can just check the length of the source literal first, and allocate a buffer of sufficient size.

strlcpy is a lot like strncpy in the sense that its name encourages programmers to use it in contexts where it is unsuitable. It should really have been given different name (strtrunc, perhaps) to make the intended use more obvious.

Name: Anonymous 2015-05-11 0:37

>>17
While this argument would convince me otherwise, doing an extra strlen() doesn't sound like a good idea from either a SLOC conservation or maintainability standpoint. I'd argue efficiency if it were still 1993.

Isn't all this raging for length-prefix strings a newbie thing, anyway? Judging from the way it seems to be about establishing rules and then following them, as though this permitted construction of any program (besides the dangerously defective ones) at the same time as exclusion of the parenthesized class.

Name: Anonymous 2015-05-11 0:42

>>17
... it's like, at this rate we might as well call strdup() and asprintf(), since we're going to be playing with the malloc heap anyway and ZOMG formatted outputs it's like backing a FILE with a resizing character buffer and doing fprintf() into it as though this was actually Java.

(that forth a while back seems to have had a throwback effect. "playing with the malloc heap", indeed. daddy cool save me.)

Name: Cudder !cXCudderUE 2015-05-11 2:08

So what's the New Improved Method to replace strlcpy(buffer, "the default value", size_of_buffer);, then?

See >>4

You'd be better off using a pointer (which is nulled by default) and this somewhere else:

buffer? buffer : "the default value"

Name: Anonymous 2015-05-11 2:39

>>17
If you were so inclined, you could define the string as a const char[] and use sizeof to determine its length, no need to type the literal twice or incur any runtime cost. stlen on a char * just makes it easier to change if you want to use something other than a constant string down the road.

>>20
I assume buffer in this example needs to escape the scope where the strlcpy is done - otherwise I agree totally.

Name: Anonymous 2015-05-11 6:13

dubsdubsdubsdubsdubs

Name: Three Star Programmer * * * 2016-11-13 0:31

>>3
Good to know that after 40 years non-C programmers still need to use n+log(n) memory to store a string.

Name: Anonymous 2016-11-13 0:47

strlcpy is shit

Name: Anonymous 2016-11-13 1:28

Now, strncpy is nasty too, because of the two main flaws:
- no guaranteed NUL at the end
- crazy "fill with NUL" at the end

What the fuck am I reading?

Name: Anonymous 2016-11-13 7:11

>>25
READ DA FUCKING STANDARD!!

strncpy(d, s, n) always writes n characters and pads with zeroes if necessary. However, it doesn't write a terminating NUL, when strlen(s) >= n. There are some easy fixes to this, though.

Name: Anonymous 2016-11-13 9:10

>>26 I don't understand the standard library worship.
There is nothing preventing you rolling your own functions and its trivial to rewrite them. Str(n)cpy/memcpy is the most trivial thing the library offers.

Name: Anonymous 2016-11-13 10:32

>>27
I don't understand the standard library worship.
In this case, it's not worship but rather knowing your shit (or just looking it up) before asking any questions.

There is nothing preventing you rolling your own functions and its trivial to rewrite them.
This isn't always true, even for such ``trivial'' functions: bugs hide everywhere, especially when you want optimize some of this stuff (which is usually done because it's very rewarding when string handling appears almost anywhere).

Name: Anonymous 2016-11-13 15:50

Can't we just delete all C libraries and start again?

Name: Anonymous 2016-11-13 17:23

>>29
No, it's 2015 for fucks sake!

Name: Anonymous 2016-11-13 17:40

>>29
Yes and that's what Rob Pike was supposed to do.
Too bad that he failed us all in the end.

Name: Anonymous 2016-11-13 19:17

>>22
That's some pretty nice dubs you got there.

Name: Anonymous 2016-11-13 19:58

>>29
Software won't work until you delete the C language too.

Don't change these.
Name: Email:
Entire Thread Thread List