lib/path: add ul_path_read_buffer()
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
e74e5401e1
commit
7eb8e47bcd
|
@ -74,6 +74,10 @@ int ul_path_read_string(struct path_cxt *pc, char **str, const char *path);
|
|||
int ul_path_readf_string(struct path_cxt *pc, char **str, const char *path, ...)
|
||||
__attribute__ ((__format__ (__printf__, 3, 4)));
|
||||
|
||||
int ul_path_read_buffer(struct path_cxt *pc, char *buf, size_t bufsz, const char *path);
|
||||
int ul_path_readf_buffer(struct path_cxt *pc, char *buf, size_t bufsz, const char *path, ...)
|
||||
__attribute__ ((__format__ (__printf__, 4, 5)));
|
||||
|
||||
int ul_path_scanf(struct path_cxt *pc, const char *path, const char *fmt, ...);
|
||||
int ul_path_scanff(struct path_cxt *pc, const char *path, va_list ap, const char *fmt, ...)
|
||||
__attribute__ ((__format__ (__scanf__, 4, 5)));
|
||||
|
|
29
lib/path.c
29
lib/path.c
|
@ -565,6 +565,35 @@ int ul_path_readf_string(struct path_cxt *pc, char **str, const char *path, ...)
|
|||
return ul_path_read_string(pc, str, p);
|
||||
}
|
||||
|
||||
int ul_path_read_buffer(struct path_cxt *pc, char *buf, size_t bufsz, const char *path)
|
||||
{
|
||||
int rc = ul_path_read(pc, buf, bufsz - 1, path);
|
||||
if (rc < 0)
|
||||
return rc;;
|
||||
|
||||
/* Remove tailing newline (usuall in sysfs) */
|
||||
if (rc > 0 && *(buf + rc - 1) == '\n')
|
||||
--rc;
|
||||
|
||||
buf[rc] = '\0';
|
||||
return rc;
|
||||
}
|
||||
|
||||
int ul_path_readf_buffer(struct path_cxt *pc, char *buf, size_t bufsz, const char *path, ...)
|
||||
{
|
||||
const char *p;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, path);
|
||||
p = ul_path_mkpath(pc, path, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (!p)
|
||||
return -EINVAL;
|
||||
|
||||
return ul_path_read_buffer(pc, buf, bufsz, p);
|
||||
}
|
||||
|
||||
int ul_path_scanf(struct path_cxt *pc, const char *path, const char *fmt, ...)
|
||||
{
|
||||
FILE *f;
|
||||
|
|
Loading…
Reference in New Issue