[go: up one dir, main page]

File: foo.c

package info (click to toggle)
criterion 2.4.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 3,864 kB
  • sloc: ansic: 17,945; cpp: 774; python: 74; makefile: 25; sh: 19
file content (31 lines) | stat: -rw-r--r-- 785 bytes parent folder | download | duplicates (2)
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
#include <stdlib.h>

#include "foo.h"

size_t foo_strlen(const char *src)
{
    size_t size = 0;
    for (; *src; ++src)
        ++size;
    return size;
}

char *foo_strcpy(char *restrict dst, const char *restrict src)
{
    char *ret = dst;
    for (; *src; ++src, ++dst)
        *dst = *src;
    /* this is buggy for the purpose of this sample: the commented line below
     * should be uncommented for all the tests to pass correctly. */
    //*dst = 0;
    return ret;
}

char *foo_strdup(const char *src)
{
    /* This implementation does not handle NULL at all: the commented line
     * below should be uncommented for all the tests to pass correctly. */
    //if (!src) return NULL;
    char *out = malloc(foo_strlen(src) + 1);
    return out ? foo_strcpy(out, src) : NULL;
}