]>
Commit | Line | Data |
---|---|---|
84980ee0 RN |
1 | /* |
2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. | |
3 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). | |
4 | * Written by Brian Behlendorf <behlendorf1@llnl.gov>. | |
5 | * UCRL-CODE-235197 | |
6 | * | |
7 | * This file is part of the SPL, Solaris Porting Layer. | |
8 | * | |
9 | * The SPL is free software; you can redistribute it and/or modify it | |
10 | * under the terms of the GNU General Public License as published by the | |
11 | * Free Software Foundation; either version 2 of the License, or (at your | |
12 | * option) any later version. | |
13 | * | |
14 | * The SPL is distributed in the hope that it will be useful, but WITHOUT | |
15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 | * for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License along | |
20 | * with the SPL. If not, see <http://www.gnu.org/licenses/>. | |
21 | */ | |
22 | ||
23 | #ifndef _SPL_STRING_H | |
24 | #define _SPL_STRING_H | |
25 | ||
d465fc58 | 26 | #include <linux/string.h> |
84980ee0 RN |
27 | |
28 | /* Fallbacks for kernel missing strlcpy */ | |
29 | #ifndef HAVE_KERNEL_STRLCPY | |
30 | ||
31 | #if defined(HAVE_KERNEL_STRSCPY) | |
32 | /* | |
33 | * strscpy is strlcpy, but returns an error on truncation. strlcpy is defined | |
34 | * to return strlen(src), so detect error and override it. | |
35 | */ | |
36 | static inline size_t | |
37 | strlcpy(char *dest, const char *src, size_t size) | |
38 | { | |
39 | ssize_t ret = strscpy(dest, src, size); | |
40 | if (likely(ret > 0)) | |
41 | return ((size_t)ret); | |
42 | return (strlen(src)); | |
43 | } | |
44 | #else | |
45 | #error "no strlcpy fallback available" | |
46 | #endif | |
47 | ||
48 | #endif /* HAVE_KERNEL_STRLCPY */ | |
49 | ||
50 | #endif /* _SPL_STRING_H */ |