Stringfns is a small C library which supports some common operations on strings. All the functions will automatically allocated enough space in the heap for their results, rather than relying on the caller knowing in advance how big the result may be (which is often inconvenient and sometimes completely impractical).
It is a logical companion to Pathfns.
Programs that use any of the Stringfns functions should use
#include <stringfns.h>
in source files and -lstringfns when linking.
The following functions are implemented:
char *s_cat(const char *s1, ...) |
Concatenate one or more source strings. |
int s_gets(char **strp, FILE *fp); |
Read a line from a stream. |
int s_split(const char *s, char ***strp, int sep, int empty); |
Split a string into components |
int s_sprintf(char **strp, const char *fmt, ...); |
Equivalent to sprintf but allocates a buffer for the result. |
char *s_strdup(const char *s); |
Copy a string to a newly allocated string. |
char *s_strndup(const char *s, size_t n); |
Copy the start of a string to a newly allocated string. |
char *s_extract(const char *s, size_t pos, size_t n); |
Copy a substring to a newly allocated string. |
void s_afree(char **array, size_t n); |
Free the elements of an array of strings. |
In all cases, returned strings are allocated with malloc and include a null terminator.
Follow the links above to the man pages, or consult the versions included in the distribution, for full details.
I've tested this package under Debian GNU/Linux "woody" and FreeBSD 4.5. It is intended to work on a wide range of UNIX-like platforms. Currently it requires the operating system to have its own vsnprintf function.
The latest version is stringfns-0.1.1.tar.gz.
You can also look at the CVS repository at http://www.chiark.greenend.org.uk/ucgi/~richardk/cvsweb/stringfns/.
Stringfns is Copyright © 2002 Richard Kettlewell
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA