kvm tools, setup: Create private directory
[linux-2.6/next.git] / tools / kvm / util.c
blob4efbce9e25b47aeb8b6d4052f111e280d51aa604
1 /*
2 * Taken from perf which in turn take it from GIT
3 */
5 #include "kvm/util.h"
7 static void report(const char *prefix, const char *err, va_list params)
9 char msg[1024];
10 vsnprintf(msg, sizeof(msg), err, params);
11 fprintf(stderr, " %s%s\n", prefix, msg);
14 static NORETURN void die_builtin(const char *err, va_list params)
16 report(" Fatal: ", err, params);
17 exit(128);
20 static void error_builtin(const char *err, va_list params)
22 report(" Error: ", err, params);
25 static void warn_builtin(const char *warn, va_list params)
27 report(" Warning: ", warn, params);
30 static void info_builtin(const char *info, va_list params)
32 report(" Info: ", info, params);
35 void die(const char *err, ...)
37 va_list params;
39 va_start(params, err);
40 die_builtin(err, params);
41 va_end(params);
44 int pr_error(const char *err, ...)
46 va_list params;
48 va_start(params, err);
49 error_builtin(err, params);
50 va_end(params);
51 return -1;
54 void pr_warning(const char *warn, ...)
56 va_list params;
58 va_start(params, warn);
59 warn_builtin(warn, params);
60 va_end(params);
63 void pr_info(const char *info, ...)
65 va_list params;
67 va_start(params, info);
68 info_builtin(info, params);
69 va_end(params);
72 void die_perror(const char *s)
74 perror(s);
75 exit(1);
78 /**
79 * strlcat - Append a length-limited, %NUL-terminated string to another
80 * @dest: The string to be appended to
81 * @src: The string to append to it
82 * @count: The size of the destination buffer.
84 size_t strlcat(char *dest, const char *src, size_t count)
86 size_t dsize = strlen(dest);
87 size_t len = strlen(src);
88 size_t res = dsize + len;
90 DIE_IF(dsize >= count);
92 dest += dsize;
93 count -= dsize;
94 if (len >= count)
95 len = count - 1;
97 memcpy(dest, src, len);
98 dest[len] = 0;
100 return res;