aboutsummaryrefslogtreecommitdiff
path: root/8.1/main.c
blob: e3e5dd1f7d3f4f1cbffdc85ad687ac98da429193 (plain) (blame)
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
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "filecopy.h"
#include "error.h"

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

	if (argc == 1) {
		filecopy(STDIN_FILENO, STDOUT_FILENO);
	} else {
		while (--argc > 0) {
			if ((fd = open(*++argv, O_RDONLY)) == -1) {
				error("cp: can't open %s", *argv);
			} else {
				filecopy(fd, STDOUT_FILENO);
				close(fd);
			}
		}
	}

	return 0;
}