autoconf
[Top][All Lists]
Advanced

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

String functions with end pointers?


From: Paul D. Smith
Subject: String functions with end pointers?
Date: 25 Apr 2006 02:19:37 -0400
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4

Hi all;

I'm working on "const-ifying" my GNU package, now that I've finally
taken the leap and abandoned support for K&R compilers.

One thing I've discovered is that there are a number of places in my
code where strings are written to ONLY to stick a nul character to end a
string, so that the code can then use the normal string functions like
strchr() etc.

In other words, a buffer and a length are passed to a function, and the
function will save the character at buf[length] then replace it with
'\0', then proceed to parse the buffer using str*() functions.  After
it's done the function replaces the saved character.


I'd really like to change this so that it's not necessary to set '\0',
preferably without making a local copy of the buffer (for efficiency's
sake) and doing that means abandoning the standard str*() functions.

I could use the length, with strn*() functions (although many are
missing obviously).  But the problem there is I need to keep updating
the length as I move through the buffer, which is a drag.


I'd much prefer to keep a pointer to the end of the buffer: this won't
change so it doesn't need to be managed.  For example, something like:

    char *strpchr(const char *str, const char *endp, int c);

or whatever.

Of course, there aren't any standard str*() or mem*() functions that I'm
aware of that use an end pointer instead of a length.

Are there any such functions in GLIB or similar?  Do people know of
similar functions in other OS's etc.?  If not, and I wanted to think
about creating some, what kind of naming convention would be
appropriate?  I thought of strp*() but I don't know.


Just curious...

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.paulandlesley.org
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist




reply via email to

[Prev in Thread] Current Thread [Next in Thread]