File: s_util.c

package info (click to toggle)
linkchecker 5.2-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,508 kB
  • ctags: 3,805
  • sloc: python: 22,666; lex: 1,114; yacc: 785; makefile: 276; ansic: 95; sh: 68; sql: 19; awk: 4
file content (52 lines) | stat: -rw-r--r-- 1,345 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 *  linux/lib/string.c
 *
 *  Copyright (C) 1991, 1992  Linus Torvalds
 */
#include "Python.h"

#if !defined(HAVE_STRLCPY)
/**
 * strlcpy - Copy a %NUL terminated string into a sized buffer
 * @dst: Where to copy the string to
 * @src: Where to copy the string from
 * @size: size of destination buffer
 *
 * Compatible with *BSD: the result is always a valid
 * NUL-terminated string that fits in the buffer (unless,
 * of course, the buffer size is zero). It does not pad
 * out the result like strncpy() does.
 */
size_t strlcpy (char *dst, const char *src, size_t size)
{
    size_t ret = strlen(src);
    if (size > 0) {
        size_t len = (ret >= size) ? size-1 : ret;
        Py_MEMCPY(dst, src, len);
        dst[len] = '\0';
    }
    return ret;
}
#endif /* !HAVE_STRLCPY */

#if !defined(HAVE_STRLCAT)
/**
 * strlcat - Append a length-limited, %NUL-terminated string to another
 * @dst: The string to be appended to
 * @src: The string to append to it
 * @size: The size of the destination buffer.
 */
size_t strlcat (char *dst, const char *src, size_t size)
{
    size_t dsize = strlen(dst);
    size_t len = strlen(src);
    size_t res = dsize + len;
    dst += dsize;
    size -= dsize;
    if (len >= size)
        len = size-1;
    Py_MEMCPY(dst, src, len);
    dst[len] = '\0';
    return res;
}
#endif /* !HAVE_STRLCAT */