File: test_strerrorlen_s.c

package info (click to toggle)
safeclib 3.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,832 kB
  • sloc: ansic: 52,639; makefile: 1,271; perl: 528; sh: 518
file content (55 lines) | stat: -rw-r--r-- 1,442 bytes parent folder | download | duplicates (3)
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
53
54
55
/*------------------------------------------------------------------
 * test_strerrorlen_s
 * File 'str/strerrorlen_s.c'
 * Lines executed:100.00% of 3
 *
 *
 *------------------------------------------------------------------
 */

#include "test_private.h"
#include "safe_str_lib.h"
#include <errno.h>

#ifndef ELAST
#define ELAST 100
#endif
int test_strerrorlen_s(void);

int test_strerrorlen_s(void) {
    size_t len;
    int i;
    const char *buf;
    int errs = 0;

    /*--------------------------------------------------*/

    for (i = 0; i <= ELAST; i++) {
        len = strerrorlen_s(i);
        if (!len) {
            if ((buf = strerror(i))) {
                debug_printf("%s %u  Error empty strerrorlen_s(%d) \"%s\" \n",
                             __FUNCTION__, __LINE__, i, buf);
                errs++;
            }
        } else {
            buf = strerror(i);
            if (strlen(buf) != len) {
                debug_printf(
                    "%s %u  Wrong strerrorlen_s(%d) => %d != %d, \"%s\" \n",
                    __FUNCTION__, __LINE__, i, (int)len, (int)strlen(buf), buf);
                errs++;
            }
        }
    }

    /*--------------------------------------------------*/

    return (errs);
}

#ifndef __KERNEL__
/* simple hack to get this to work for both userspace and Linux kernel,
   until a better solution can be created. */
int main(void) { return (test_strerrorlen_s()); }
#endif