2 * (c) 2010 Cyrill Gorcunov, gorcunov@gmail.com
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or (at
7 * your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 #include <sys/param.h>
29 #include <sys/types.h>
33 static void report(const char *prefix
, const char *err
, va_list params
)
36 vsnprintf(msg
, sizeof(msg
), err
, params
);
37 fprintf(stderr
, " %s%s\n", prefix
, msg
);
40 static NORETURN
void die_builtin(const char *err
, va_list params
)
42 report(" Fatal: ", err
, params
);
46 static void error_builtin(const char *err
, va_list params
)
48 report(" Error: ", err
, params
);
51 static void warn_builtin(const char *warn
, va_list params
)
53 report(" Warning: ", warn
, params
);
56 static void debug_builtin(const char *info
, va_list params
)
58 report(" Debug: ", info
, params
);
61 void die(const char *err
, ...)
65 va_start(params
, err
);
66 die_builtin(err
, params
);
70 int error(const char *err
, ...)
74 va_start(params
, err
);
75 error_builtin(err
, params
);
80 void warning(const char *warn
, ...)
84 va_start(params
, warn
);
85 warn_builtin(warn
, params
);
89 void debug(const char *info
, ...)
93 va_start(params
, info
);
94 debug_builtin(info
, params
);
98 void die_perror(const char *s
)
105 * strlcat - Append a length-limited, %NUL-terminated string to another
106 * @dest: The string to be appended to
107 * @src: The string to append to it
108 * @count: The size of the destination buffer.
110 size_t strlcat(char *dest
, const char *src
, size_t count
)
112 size_t dsize
= strlen(dest
);
113 size_t len
= strlen(src
);
114 size_t res
= dsize
+ len
;
116 DIE_IF(dsize
>= count
);
123 memcpy(dest
, src
, len
);