mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
Add dm_snprintf
This commit is contained in:
parent
7d7736b7b4
commit
9e063b223e
@ -1,6 +1,6 @@
|
|||||||
Version 1.02.10 -
|
Version 1.02.10 -
|
||||||
==============================
|
==============================
|
||||||
Add dm_split_words() and dm_split_lvm_name() to libdevmapper.
|
Add dm_snprintf(), dm_split_words() and dm_split_lvm_name() to libdevmapper.
|
||||||
Reorder mm bounds_check code to reduce window for a dmeventd race.
|
Reorder mm bounds_check code to reduce window for a dmeventd race.
|
||||||
|
|
||||||
Version 1.02.09 - 15 Aug 2006
|
Version 1.02.09 - 15 Aug 2006
|
||||||
|
@ -111,3 +111,4 @@ dm_set_selinux_context
|
|||||||
dm_task_set_geometry
|
dm_task_set_geometry
|
||||||
dm_split_lvm_name
|
dm_split_lvm_name
|
||||||
dm_split_words
|
dm_split_words
|
||||||
|
dm_snprintf
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#define LIB_DEVICE_MAPPER_H
|
#define LIB_DEVICE_MAPPER_H
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#ifdef linux
|
#ifdef linux
|
||||||
@ -601,4 +602,9 @@ int dm_split_words(char *buffer, unsigned max,
|
|||||||
unsigned ignore_comments, /* Not implemented */
|
unsigned ignore_comments, /* Not implemented */
|
||||||
char **argv);
|
char **argv);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns -1 if buffer too small
|
||||||
|
*/
|
||||||
|
int dm_snprintf(char *buf, size_t bufsize, const char *format, ...);
|
||||||
|
|
||||||
#endif /* LIB_DEVICE_MAPPER_H */
|
#endif /* LIB_DEVICE_MAPPER_H */
|
||||||
|
@ -99,3 +99,25 @@ int dm_split_lvm_name(struct dm_pool *mem, const char *dmname,
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* On error, up to glibc 2.0.6, snprintf returned -1 if buffer was too small;
|
||||||
|
* From glibc 2.1 it returns number of chars (excl. trailing null) that would
|
||||||
|
* have been written had there been room.
|
||||||
|
*
|
||||||
|
* dm_snprintf reverts to the old behaviour.
|
||||||
|
*/
|
||||||
|
int dm_snprintf(char *buf, size_t bufsize, const char *format, ...)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, format);
|
||||||
|
n = vsnprintf(buf, bufsize, format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
if (n < 0 || (n > bufsize - 1))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user