File: libiberty.c

package info (click to toggle)
libiberty 20230104-1
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 8,648 kB
  • sloc: ansic: 88,404; sh: 3,971; cpp: 1,678; makefile: 1,628; perl: 302
file content (68 lines) | stat: -rw-r--r-- 1,436 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
56
57
58
59
60
61
62
63
64
65
66
67
68
#define _POSIX_C_SOURCE 200809L
#include <errno.h>
#include <fcntl.h>
#include <libiberty/libiberty.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int main(void) {
	char *s = concat("foo", "bar", "bat", "baz", "cat", "ding", "dong", NULL);
	if(puts(s) == EOF) {
		perror("Failed to print string");
		abort();
	}
	free(s);

	if(faccessat(AT_FDCWD, "/proc/self/fd/0", R_OK, AT_EACCESS) != -1) {
		const int zerofd = open("/proc/self/fd/0", O_RDONLY);
		if(zerofd == -1) {
			perror("Failed to open /proc/self/fd/0");
			abort();
		}
		if(!fdmatch(0, zerofd)) {
			fputs("fds do not match!\n", stderr);
			abort();
		}
		if(close(zerofd) == -1) {
			perror("Failed to close file descriptor");
			abort();
		}
	}

	if(puts(getpwd()) == EOF) {
		perror("Failed to print working directory");
		abort();
	}
	if(EINVAL != strtoerrno("EINVAL")) {
		fputs("strtoerrno failed\n", stderr);
		abort();
	}
	if(strcmp("ERANGE", strerrno(ERANGE))) {
		fputs("strerrno failed\n", stderr);
		abort();
	}
	if(strcmp("SIGSEGV", strsigno(SIGSEGV))) {
		fputs("strsigno failed\n", stderr);
		abort();
	}
	if(SIGABRT != strtosigno("SIGABRT")) {
		fputs("strtosigno failed\n", stderr);
		abort();
	}

	s = xasprintf("%d", 0);
	if(puts(s) == EOF) {
		perror("Failed to print string");
		abort();
	}
	if(strcmp("0", s)) {
		fputs("xasprintf gave unexpected results\n", stderr);
		abort();
	}
	free(s);


}