Indention of code
[netsniff-ng.git] / src / strlcpy.c
blobf4d1d74d278f6938e9f227ac068223d21df04b52
1 /*
2 * Copyright (C) 2009, 2010 Daniel Borkmann <daniel@netsniff-ng.org> and
3 * Emmanuel Roullit <emmanuel@netsniff-ng.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
21 * Copyright (C) 1991, 1992 Linus Torvalds
23 * This program is free software; you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation; either version 2 of the License, or (at
26 * your option) any later version.
28 * This program is distributed in the hope that it will be useful, but
29 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
30 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
31 * for more details.
33 * You should have received a copy of the GNU General Public License along
34 * with this program; if not, write to the Free Software Foundation, Inc.,
35 * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
38 /* xmalloc.c taken from the Linux kernel and adapted */
40 #include <string.h>
41 #include "strlcpy.h"
43 size_t strlcpy(char *dest, const char *src, size_t size)
45 size_t ret = strlen(src);
47 if (size) {
48 size_t len = (ret >= size) ? size - 1 : ret;
49 memcpy(dest, src, len);
50 dest[len] = '\0';
53 return ret;