DragonFly BSD
DragonFly submit List (threaded) for 2006-06
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: Add strndup


From: Matthew Dillon <dillon@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 21 Jun 2006 01:20:24 -0700 (PDT)

:Why not call it memdup instead and drop the termination? String
:functions for standard C, as broken as they are, are all based around
:having a null terminator, and in your case you're actually basing
:entirely off a length (but allocating for length + 1 which is very
:counter-intuitive). Not that this function really achieves anything to
:begin with...

    A memdup that is not string-oriented is a fine idea, but it 
    would not be something we would add to libc unless there were
    a pre-existing reasonably standardized function somewhere that
    did that sort of operation.  It's only a few lines of code but
    the problem vis-a-vie putting things into libc is standardization.

:I never cared for C-style strings. To set a length for them you have
:to modify them, and this means you have to re-allocate if doing
:read-only tokenizing or regex extraction. In my own code I define a
:...
:  -- Dmitri Nikulin

    People are welcome to implement their own string handling functions,
    but we aren't going to put things into libc that are not standardized
    across multiple platforms.  C's string handling functions aren't the
    best in the world, but they aren't that bad either.  \0 termination
    is not a big deal and strlen() is not a big deal either. 

    Programs which manipulate very long strings often keep track of
    the length of the string themselves.  For example, the cpdup utility
    manipulates potentially very long file paths and it caches index points
    into the path strings to avoid having to call strlen() on the whole
    string.

					-Matt
					Matthew Dillon 
					<dillon@xxxxxxxxxxxxx>



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]