Annex K tanking badly was just sad. At least they finally standardized strdup().
Annex K tanking badly was just sad. At least they finally standardized strdup().
Some of the string functions, like strtok() or strcat(), and I would also include strdup(), are broken beyond repair and should simply not be used. The only way to "fix" the library would be to remove these functions, but I assume this would create more trouble with legacy code than it's worth.
C strings are mostly a useful storage format for small strings, including string literals, and as a "default" string type for the little basic functionality that is expected to be part of C to support a small program growing up - including printf() and friends.
For longer strings, you are expected to build datatypes that fit your usecase, and that includes decisions about memory management. It should not be the responsibility of the language to make these decisions for you.
It's something that I use. Maybe not frequently, but I definitely use it.
Also, it is in no way equivalent to malloc(strlen(x)). You're off by one byte and you've not copied any of the string.
At least, glob() has its own globfree() function, leaving room for slightly more mindful organization.