4.104.114.84.95
Line | |
---|
1 | /* |
---|
2 | * utils.c - various utility functions used in pppd. |
---|
3 | * |
---|
4 | * Copyright (c) 1999 The Australian National University. |
---|
5 | * All rights reserved. |
---|
6 | * |
---|
7 | * Redistribution and use in source and binary forms are permitted |
---|
8 | * provided that the above copyright notice and this paragraph are |
---|
9 | * duplicated in all such forms and that any documentation, |
---|
10 | * advertising materials, and other materials related to such |
---|
11 | * distribution and use acknowledge that the software was developed |
---|
12 | * by the Australian National University. The name of the University |
---|
13 | * may not be used to endorse or promote products derived from this |
---|
14 | * software without specific prior written permission. |
---|
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
---|
16 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
---|
17 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
---|
18 | */ |
---|
19 | |
---|
20 | #if HAVE_CONFIG_H |
---|
21 | #include "config.h" |
---|
22 | #endif |
---|
23 | |
---|
24 | #include <string.h> |
---|
25 | |
---|
26 | #ifndef HAVE_STRLCPY |
---|
27 | /* |
---|
28 | * strlcpy - like strcpy/strncpy, doesn't overflow destination buffer, |
---|
29 | * always leaves destination null-terminated (for len > 0). |
---|
30 | */ |
---|
31 | size_t |
---|
32 | strlcpy(dest, src, len) |
---|
33 | char *dest; |
---|
34 | const char *src; |
---|
35 | size_t len; |
---|
36 | { |
---|
37 | size_t ret = strlen(src); |
---|
38 | |
---|
39 | if (len != 0) { |
---|
40 | if (ret < len) |
---|
41 | strcpy(dest, src); |
---|
42 | else { |
---|
43 | strncpy(dest, src, len - 1); |
---|
44 | dest[len-1] = 0; |
---|
45 | } |
---|
46 | } |
---|
47 | return ret; |
---|
48 | } |
---|
49 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.