1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

cherry picked (v)strap functions from opal-async branch

This commit is contained in:
Steffen Vogel 2015-03-18 15:38:06 +01:00
parent 84686ffacb
commit 51a1b42f46
2 changed files with 28 additions and 0 deletions

View file

@ -68,6 +68,15 @@ void epoch_reset();
*/
void print(enum log_level lvl, const char *fmt, ...);
/** Safely append a format string to an existing string.
*
* This function is similar to strlcat() from BSD.
*/
int strap(char *dest, size_t size, const char *fmt, ...);
/** Variable arguments (stdarg) version of strap() */
int vstrap(char *dest, size_t size, const char *fmt, va_list va);
/** Convert integer to cpu_set_t.
*
* @param set A cpu bitmask

View file

@ -35,6 +35,25 @@ void epoch_reset()
clock_gettime(CLOCK_REALTIME, &epoch);
}
int strap(char *dest, size_t size, const char *fmt, ...)
{
int ret;
va_list ap;
va_start(ap, fmt);
ret = vstrap(dest, size, fmt, ap);
va_end(ap);
return ret;
}
int vstrap(char *dest, size_t size, const char *fmt, va_list ap)
{
int len = strlen(dest);
return vsnprintf(dest + len, size - len, fmt, ap);
}
void print(enum log_level lvl, const char *fmt, ...)
{
struct timespec ts;