String functions with end pointers?

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

 



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 <psmith@xxxxxxx>          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


_______________________________________________
Autoconf mailing list
Autoconf@xxxxxxx
http://lists.gnu.org/mailman/listinfo/autoconf

[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux