File: cat.c

package info (click to toggle)
proot 5.1.0-1.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, trixie
  • size: 2,228 kB
  • sloc: ansic: 16,491; sh: 1,327; asm: 41; makefile: 8
file content (36 lines) | stat: -rw-r--r-- 596 bytes parent folder | download | duplicates (5)
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
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

int main(int argc, char *argv[])
{
	int status;
	int fd;
	int i;

	for (i = 1; i < argc; i++) {
		char buffer[1024];

		fd = open(argv[i], O_RDONLY);
		if (fd < 0) {
			perror("open(2)");
			exit(EXIT_FAILURE);
		}

		while ((status = read(fd, buffer, sizeof(buffer))) > 0 && write(1, buffer, status) == status)
			errno = 0;

		if (errno != 0) {
			perror("read(2)/write(2)");
			exit(EXIT_FAILURE);
		}

		(void) close(fd);
	}

	exit(EXIT_SUCCESS);
}