libendstr
Libendstr is a minimalistic string library that provides some of the standard
C string functions with a slightly modified API. The new API is designed to
make building a string by a sequence of appends both efficient and readable.
concepts
The user code has:
- a char *buffer; it's most often a static buffer with a hardwired size; this is always a pointer pointing to the first byte of the buffer, whether it's in use or not;
- the (current) total (allocated) size of the buffer, to avoid buffer overruns with the 'n' series of functions;
- a char *end pointer pointing to the current end of the buffer; this points to the character where the next append will start; if it is NULL, the buffer is already full and no further append is possible;
API conventions:
- functions always returns the new end pointer or NULL if the buffer is not large enough to host all new data in the call, and ...;
- ... atomic functions will not touch the buffer in that case (guaranteeing that the buffer has only full "transactions" and maybe some empty space at the end)
- ... non-atomic functions will write as much data as possible (resulting in a full buffer, with a partial "transaction" at the end)
- safe functions guarantee that the buffer is never overrun; for this they get the begin, the current end and the total length of the buffer;
- unsafe functions get only the end of the buffer (and not start or length); the user code made sure by other means that there won't be buffer overrun thus libendstr makes no checks;
- cstring functions always guarantee to preserve/place the terminator \0, even upon failure, but without buffer overrun; 'mem' functions never add a terminator
call summary
call | is safe? | is atomic? | is cstring?
|
---|
end_strcpy | no | no | yes
|
end_strncpy | yes | no | yes
|
end_sprintf | no | no | yes
|
end_snprintf | yes | no | yes
|
end_memcpy | no | no | no
|
end_memncpy | yes | no | no
|
end_memset | no | no | no
|
end_memnset | yes | no | no
|
end_memacpy | yes | yes | no
|
end_memaset | yes | yes | no
|
end_strend | no | n/a (read-only function)
|
end_strnend | yes | n/a (read-only function)
|
Compatibility aliases:
call | is safe? | is atomic? | is cstring?
|
---|
end_stpcpy | no | no | yes
|
end_stnpcpy | yes | no | yes
|
end_stpcat | no | no | yes
|
end_stnpcat | yes | no | yes
|
call details
Please read endstr.h
download & contact
svn checkout svn://repo.hu/libendstr
Contact the author:
email or IRC