xref: /openbsd-src/regress/lib/libc/strerror/strerror_test.c (revision b725ae7711052a2233e31a66fefb8a752c388d7a)
1 /* $OpenBSD: strerror_test.c,v 1.2 2004/05/02 22:34:29 espie Exp $ */
2 /*
3  * Copyright (c) 2004 Marc Espie <espie@cvs.openbsd.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 #include <string.h>
18 #include <stdio.h>
19 #include <limits.h>
20 #include <errno.h>
21 
22 void
23 check_strerror_r(int val)
24 {
25 	char buffer[NL_TEXTMAX];
26 	int i, r;
27 
28 	memset(buffer, 0, sizeof(buffer));
29 	(void)strerror_r(val, NULL, 0);	/* XXX */
30 	for (i = 0; i < 25; i++) {
31 		r = strerror_r(val, buffer, i);
32 		printf("%d %d %lu: %s\n", i, r, strlen(buffer), buffer);
33 	}
34 }
35 
36 int
37 main()
38 {
39 	printf("%s\n", strerror(21345));
40 	printf("%s\n", strerror(-21345));
41 	printf("%s\n", strerror(0));
42 	printf("%s\n", strerror(INT_MAX));
43 	printf("%s\n", strerror(INT_MIN));
44 	printf("%s\n", strerror(EPERM));
45 	check_strerror_r(EPERM);
46 	check_strerror_r(21345);
47 	return 0;
48 }
49