Cross-platform string manipulation functions. More...
Macros | |
#define | DDvsnprintf |
#define | newstring(x) |
#define | strtod(a, b) |
Functions | |
int | vsnprintf (char *str, size_t size, const char *fmt, va_list ap) |
int | snprintf (char *str, size_t size, const char *fmt,...) |
size_t | strlcat (char *dst, const char *src, size_t siz) |
size_t | strlcpy (char *dst, const char *src, size_t siz) |
char * | DDImage_newstring (const char *) |
double | DDImage_strtod (const char *p, char **endptr) |
Cross-platform string manipulation functions.
You should use this file instead of <string.h>, <stdlib.h>, or <stdio.h>. This defines replacements for several standard library functions to produce the same behavior on all platforms (mostly to copy Linux features to Windows). It also defines functions from BSD that make string manipulation that does not overflow buffers much easier.
int vsnprintf | ( | char * | str, |
size_t | size, | ||
const char * | fmt, | ||
va_list | ap | ||
) |
Print at most size characters (including a trailing null) into the buffer pointed to by str. Returns the number of bytes written (not including the nul). If the printout is truncated this is supposed to return the number of bytes that would have been printed, however this only works on newer Linux machines, other systems return -1 or zero.
Linux provides this function. On NT it calls _vsnprintf which is almost correct. On Irix and some other systems an emulation function is used. This emulation is rather simple and has the following bugs:
Referenced by DD::Image::Op::critical(), DD::Image::Op::debug(), DD::Image::Op::error(), DD::Image::WriteGeo::internalError(), DD::Image::ReadGeo::internalError(), DD::Image::Write::internalError(), DD::Image::Op::progressMessage(), snprintf(), and DD::Image::Op::warning().
int snprintf | ( | char * | str, |
size_t | size, | ||
const char * | fmt, | ||
... | |||
) |
Print at most size characters (including a trailing null) into the buffer pointed to by str. See vsnprintf for bugs.
References vsnprintf().
Referenced by DD::Image::plugin_binary(), DD::Image::plugin_load(), and DD::Image::plugin_load_one().
size_t strlcat | ( | char * | dst, |
const char * | src, | ||
size_t | siz | ||
) |
BSD no-buffer-overflow string concatanation function. Appends src to buffer dst of size siz (unlike strncat(), siz is the full size of dst, not space left). At most siz-1 characters will be copied. Always NUL terminates (unless siz == 0). Returns strlen(initial dst) + strlen(src); if retval >= siz, truncation occurred.
Referenced by DD::Image::Writer::Description::find().
size_t strlcpy | ( | char * | dst, |
const char * | src, | ||
size_t | siz | ||
) |
BSD no-buffer-overflow string copy function. Copy src to buffer dst of size siz. At most siz-1 characters will be copied. Always NUL terminates (unless siz == 0). Returns strlen(src); if retval >= siz, truncation occurred.
Referenced by DD::Image::GeoWriter::close(), DD::Image::Writer::Description::find(), DD::Image::WriteGeo::internalError(), DD::Image::ReadGeo::internalError(), DD::Image::Write::internalError(), DD::Image::GeoWriter::open(), DD::Image::plugin_addpath(), DD::Image::plugin_error(), DD::Image::plugin_find(), and DD::Image::plugin_load_all().
char* DDImage_newstring | ( | const char * | ) |
Equivalent to strdup() except the C++ new[] operator is used. A block of memory strlen(from)+1 is allocated and the from string is copied to it. Notice that you must use delete[] to destroy the returned value, not free()!
If NULL is passed, a NULL is returned.
It is a good idea to use this instead of strdup() so that all your memory allocations pass through the C++ new-handler.
<DDImage/DDString.h> defines newstring() as a macro that calls this. This is to avoid duplicate-symbol conflicts with libraries that define functions by the same name.
double DDImage_strtod | ( | const char * | p, |
char ** | endptr | ||
) |
Replacement for strtod() from stdlib.h
Skips all whitespace and then attempts to convert the start of the next text into a double. endptr (if not null) is changed to point at the character it stopped at. This is the same as the standard strtod() but it also recognizes:
These changes allow it to read numbers printed to a file from any platform, and to read constants that were intended for other data types.
<DDImage/string.h> defines strtod() as a macro that calls this, thus replacing the C standard library function.
©2021 The Foundry Visionmongers, Ltd. All Rights Reserved. |