git://git.onelab.eu
/
sliver-openvswitch.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Make pkidir, rundir, logdir modifiable from "configure" command line.
[sliver-openvswitch.git]
/
lib
/
util.c
diff --git
a/lib/util.c
b/lib/util.c
index
0c70710
..
72138a0
100644
(file)
--- a/
lib/util.c
+++ b/
lib/util.c
@@
-33,6
+33,7
@@
#include <config.h>
#include "util.h"
#include <config.h>
#include "util.h"
+#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@
-100,25
+101,47
@@
xstrdup(const char *s)
}
char *
}
char *
-x
asprintf(const char *format, ...
)
+x
vasprintf(const char *format, va_list args
)
{
{
- va_list args;
+ va_list args
2
;
size_t needed;
char *s;
size_t needed;
char *s;
- va_
start(args, format
);
+ va_
copy(args2, args
);
needed = vsnprintf(NULL, 0, format, args);
needed = vsnprintf(NULL, 0, format, args);
- va_end(args);
s = xmalloc(needed + 1);
s = xmalloc(needed + 1);
+ vsnprintf(s, needed + 1, format, args2);
+ va_end(args2);
+
+ return s;
+}
+
+char *
+xasprintf(const char *format, ...)
+{
+ va_list args;
+ char *s;
+
va_start(args, format);
va_start(args, format);
-
vsnprintf(s, needed + 1,
format, args);
+
s = xvasprintf(
format, args);
va_end(args);
return s;
}
va_end(args);
return s;
}
+void
+strlcpy(char *dst, const char *src, size_t size)
+{
+ if (size > 0) {
+ size_t n = strlen(src);
+ size_t n_copy = MIN(n, size - 1);
+ memcpy(dst, src, n_copy);
+ dst[n_copy] = '\0';
+ }
+}
+
void
ofp_fatal(int err_no, const char *format, ...)
{
void
ofp_fatal(int err_no, const char *format, ...)
{
@@
-138,6
+161,7
@@
ofp_fatal(int err_no, const char *format, ...)
void
ofp_error(int err_no, const char *format, ...)
{
void
ofp_error(int err_no, const char *format, ...)
{
+ int save_errno = errno;
va_list args;
fprintf(stderr, "%s: ", program_name);
va_list args;
fprintf(stderr, "%s: ", program_name);
@@
-147,6
+171,8
@@
ofp_error(int err_no, const char *format, ...)
if (err_no != 0)
fprintf(stderr, " (%s)", strerror(err_no));
putc('\n', stderr);
if (err_no != 0)
fprintf(stderr, " (%s)", strerror(err_no));
putc('\n', stderr);
+
+ errno = save_errno;
}
/* Sets program_name based on 'argv0'. Should be called at the beginning of
}
/* Sets program_name based on 'argv0'. Should be called at the beginning of