diff --git a/lib/misc/lvm-string.h b/lib/misc/lvm-string.h new file mode 100644 index 000000000..a502ce475 --- /dev/null +++ b/lib/misc/lvm-string.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2001 Sistina Software (UK) Limited. + * + * This file is released under the LGPL. + */ + +#ifndef _LVM_STRING_H +#define _LVM_STRING_H + +#include + +/* + * Different versions of glibc have different + * return values for over full buffers. + */ +static inline int lvm_snprintf(char *str, size_t size, const char *format, ...) +{ + int n; + va_list ap; + + va_start(ap, format); + n = vsnprintf(str, size, format, ap); + va_end(ap); + + if (n < 0 || n == size) + return -1; + + return n; +} + +#endif