mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-06 11:09:13 +00:00
Improve Serval instance path operations
Replace form_serval_instance_path(), which takes a single 'path' argument, with formf_serval_instance_path() and vformf_serval_instance_path(), which take printf(3)-like arguments. This supports more flexible instance path file names. FORM_SERVAL_INSTANCE_PATH() macro works as before, but reimplemented
This commit is contained in:
parent
f3cd0d8718
commit
4937757d36
19
instance.c
19
instance.c
@ -43,10 +43,25 @@ void serval_setinstancepath(const char *instancepath)
|
|||||||
thisinstancepath = strdup(instancepath);
|
thisinstancepath = strdup(instancepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
int form_serval_instance_path(char *buf, size_t bufsiz, const char *path)
|
int formf_serval_instance_path(struct __sourceloc __whence, char *buf, size_t bufsiz, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
int ret = vformf_serval_instance_path(__whence, buf, bufsiz, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int vformf_serval_instance_path(struct __sourceloc __whence, char *buf, size_t bufsiz, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
strbuf b = strbuf_local(buf, bufsiz);
|
strbuf b = strbuf_local(buf, bufsiz);
|
||||||
strbuf_path_join(b, serval_instancepath(), path, NULL);
|
strbuf_va_vprintf(b, fmt, ap);
|
||||||
|
if (!strbuf_overrun(b) && strbuf_len(b) && buf[0] != '/') {
|
||||||
|
strbuf_reset(b);
|
||||||
|
strbuf_puts(b, serval_instancepath());
|
||||||
|
strbuf_putc(b, '/');
|
||||||
|
strbuf_va_vprintf(b, fmt, ap);
|
||||||
|
}
|
||||||
if (!strbuf_overrun(b))
|
if (!strbuf_overrun(b))
|
||||||
return 1;
|
return 1;
|
||||||
WHYF("instance path overflow (strlen %lu, sizeof buffer %lu): %s",
|
WHYF("instance path overflow (strlen %lu, sizeof buffer %lu): %s",
|
||||||
|
5
serval.h
5
serval.h
@ -161,11 +161,12 @@ extern const char version_servald[];
|
|||||||
* is in scope (so that sizeof(buf) will work). Evaluates to true if the pathname fitted into
|
* is in scope (so that sizeof(buf) will work). Evaluates to true if the pathname fitted into
|
||||||
* the provided buffer, false (0) otherwise (after logging an error).
|
* the provided buffer, false (0) otherwise (after logging an error).
|
||||||
*/
|
*/
|
||||||
#define FORM_SERVAL_INSTANCE_PATH(buf, path) (form_serval_instance_path(buf, sizeof(buf), (path)))
|
#define FORM_SERVAL_INSTANCE_PATH(buf, path) (formf_serval_instance_path(__WHENCE__, buf, sizeof(buf), "%s", (path)))
|
||||||
|
|
||||||
const char *serval_instancepath();
|
const char *serval_instancepath();
|
||||||
int create_serval_instance_dir();
|
int create_serval_instance_dir();
|
||||||
int form_serval_instance_path(char *buf, size_t bufsiz, const char *path);
|
int formf_serval_instance_path(struct __sourceloc, char *buf, size_t bufsiz, const char *fmt, ...) __attribute__((format(printf,4,5)));
|
||||||
|
int vformf_serval_instance_path(struct __sourceloc, char *buf, size_t bufsiz, const char *fmt, va_list);
|
||||||
void serval_setinstancepath(const char *instancepath);
|
void serval_setinstancepath(const char *instancepath);
|
||||||
|
|
||||||
/* Basic socket operations.
|
/* Basic socket operations.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user