Re: New version of function mkdirhier()
On Fri, Jan 13, 2012 at 10:33:23AM +0100, Svante Signell wrote:
> The problem with dynamic string allocation is that you cannot free
> strings being modified by the functions, like strsep.
What ? Memory allocation has almost nothing to do with string operations
(except for strdup()). Here, strsep() modifies the string in place,
which means your buffer address doesn't change. You just have to save it
and free() it when you're done...
> Maybe you can find
> a smart solution, I haven't. Are you ever happy with code written by
> somebody else than yourself?
> BTW: what happened with the psmisc patch you promised a long time ago?
Again, that damn attitude with regard to comments. Why would we even
waste time helping you when chances are you'll just insult peolpe in
return. Of course he's happy with code he didn't write himself, when
such code is decent. You're making beginner mistakes in yours and
don't understand when a more experienced person is trying to explain
them. Worse, you make it personal. Stop it, or you'll just get ignored
by everyone who currently cares about what you're doing.
Now back to the technical stuff. I believe Guillem's solution is quite
appropriate. It solves the size problem while limiting the number of
changes, making it easier for whoever maintains the original code to
accept the patch. As for the cons you mentioned, he did answer about
that too (there is no portability issue since there are replacements
if the system doesn't provide all the non standard functions, and most
str* functions are only dangerous when misused).
Personnally, I'd advise against using srtncat(). Ever. Confusing and
almost useless since it still requires maintaining string sizes, which,
as Guillem mentioned, usually leads to more code complexity, making
the result even more confusing. Such confusion is what makes C string
operations so error prone.