Added BPF attach/detach support check.
[netsniff-ng.git] / src / strlcpy.c
blobb24142e8ea609f848eb20bbfcd4417958fd10a02
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2009, 2010 Daniel Borkmann.
5 * Subject to the GPL, version 2.
6 */
8 /*
9 * strlcpy, Copyright (C) 1991, 1992 Linus Torvalds
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or (at
14 * your option) any later version.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
26 #define _BSD_SOURCE
27 #include <string.h>
28 #include <stdio.h>
29 #include <stdarg.h>
31 #include "strlcpy.h"
33 size_t strlcpy(char *dest, const char *src, size_t size)
35 size_t ret = strlen(src);
37 if (size) {
38 size_t len = (ret >= size) ? size - 1 : ret;
39 memcpy(dest, src, len);
40 dest[len] = '\0';
43 return ret;
46 int slprintf(char *dst, size_t size, const char *fmt, ...)
48 int ret;
49 va_list ap;
51 va_start(ap, fmt);
52 ret = vsnprintf(dst, size, fmt, ap);
53 dst[size - 1] = '\0';
54 va_end(ap);
56 return ret;