|
4 | 4 | #include <cstdlib>
|
5 | 5 | #include <cstring>
|
6 | 6 |
|
7 |
| -extern "C" { |
8 |
| - |
9 |
| -#ifndef HAVE_STRLCAT |
10 |
| -/* |
11 |
| - '_cups_strlcat()' - Safely concatenate two strings. |
12 |
| -*/ |
13 |
| - |
14 |
| -size_t /* O - Length of string */ |
15 |
| -strlcat(char* dst, /* O - Destination string */ |
16 |
| - const char* src, /* I - Source string */ |
17 |
| - size_t size) /* I - Size of destination string buffer */ |
| 7 | +extern "C" |
18 | 8 | {
|
19 |
| - size_t srclen; /* Length of source string */ |
20 |
| - size_t dstlen; /* Length of destination string */ |
| 9 | +#ifndef HAVE_STRLCAT |
| 10 | + // '_cups_strlcat()' - Safely concatenate two strings. |
21 | 11 |
|
22 |
| - /* |
23 |
| - Figure out how much room is left... |
24 |
| - */ |
| 12 | + size_t /* O - Length of string */ |
| 13 | + strlcat(char* dst, /* O - Destination string */ |
| 14 | + const char* src, /* I - Source string */ |
| 15 | + size_t size) /* I - Size of destination string buffer */ |
| 16 | + { |
| 17 | + size_t srclen; /* Length of source string */ |
| 18 | + size_t dstlen; /* Length of destination string */ |
25 | 19 |
|
26 |
| - dstlen = strlen(dst); |
27 |
| - size -= dstlen + 1; |
| 20 | + // Figure out how much room is left... |
28 | 21 |
|
29 |
| - if (!size) |
30 |
| - { |
31 |
| - return (dstlen); /* No room, return immediately... */ |
32 |
| - } |
| 22 | + dstlen = strlen(dst); |
| 23 | + size -= dstlen + 1; |
33 | 24 |
|
34 |
| - /* |
35 |
| - Figure out how much room is needed... |
36 |
| - */ |
| 25 | + if (!size) |
| 26 | + { |
| 27 | + return (dstlen); /* No room, return immediately... */ |
| 28 | + } |
37 | 29 |
|
38 |
| - srclen = strlen(src); |
| 30 | + // Figure out how much room is needed... |
39 | 31 |
|
40 |
| - /* |
41 |
| - Copy the appropriate amount... |
42 |
| - */ |
| 32 | + srclen = strlen(src); |
43 | 33 |
|
44 |
| - if (srclen > size) |
45 |
| - { |
46 |
| - srclen = size; |
47 |
| - } |
| 34 | + // Copy the appropriate amount... |
48 | 35 |
|
49 |
| - memcpy(dst + dstlen, src, srclen); |
50 |
| - dst[dstlen + srclen] = '\0'; |
| 36 | + if (srclen > size) |
| 37 | + { |
| 38 | + srclen = size; |
| 39 | + } |
51 | 40 |
|
52 |
| - return (dstlen + srclen); |
53 |
| -} |
| 41 | + memcpy(dst + dstlen, src, srclen); |
| 42 | + dst[dstlen + srclen] = '\0'; |
| 43 | + |
| 44 | + return (dstlen + srclen); |
| 45 | + } |
54 | 46 | #endif /* !HAVE_STRLCAT */
|
55 | 47 |
|
56 | 48 | #ifndef HAVE_STRLCPY
|
57 |
| -/* |
58 |
| - '_cups_strlcpy()' - Safely copy two strings. |
59 |
| -*/ |
60 |
| - |
61 |
| -size_t /* O - Length of string */ |
62 |
| -strlcpy(char* dst, /* O - Destination string */ |
63 |
| - const char* src, /* I - Source string */ |
64 |
| - size_t size) /* I - Size of destination string buffer */ |
65 |
| -{ |
66 |
| - size_t srclen; /* Length of source string */ |
| 49 | + // '_cups_strlcpy()' - Safely copy two strings. |
| 50 | + |
| 51 | + size_t /* O - Length of string */ |
| 52 | + strlcpy(char* dst, /* O - Destination string */ |
| 53 | + const char* src, /* I - Source string */ |
| 54 | + size_t size) /* I - Size of destination string buffer */ |
| 55 | + { |
| 56 | + size_t srclen; /* Length of source string */ |
67 | 57 |
|
68 |
| - /* |
69 |
| - Figure out how much room is needed... |
70 |
| - */ |
| 58 | + // Figure out how much room is needed... |
71 | 59 |
|
72 |
| - size--; |
| 60 | + size--; |
73 | 61 |
|
74 |
| - srclen = strlen(src); |
| 62 | + srclen = strlen(src); |
75 | 63 |
|
76 |
| - /* |
77 |
| - Copy the appropriate amount... |
78 |
| - */ |
| 64 | + // Copy the appropriate amount... |
79 | 65 |
|
80 |
| - if (srclen > size) |
81 |
| - { |
82 |
| - srclen = size; |
83 |
| - } |
| 66 | + if (srclen > size) |
| 67 | + { |
| 68 | + srclen = size; |
| 69 | + } |
84 | 70 |
|
85 |
| - memcpy(dst, src, srclen); |
86 |
| - dst[srclen] = '\0'; |
| 71 | + memcpy(dst, src, srclen); |
| 72 | + dst[srclen] = '\0'; |
87 | 73 |
|
88 |
| - return (srclen); |
89 |
| -} |
| 74 | + return (srclen); |
| 75 | + } |
90 | 76 | #endif /* !HAVE_STRLCPY */
|
91 | 77 |
|
92 |
| -} // extern "C" |
| 78 | +} // extern "C" |
0 commit comments