Support for cross-compiling kernel modules
[zfs.git] / tests / zfs-tests / cmd / cp_files.c
blob9af64a112631de2425a975a67ded3eb9b614dfde
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include <dirent.h>
8 #include <errno.h>
9 #include <string.h>
11 int
12 main(int argc, char *argv[])
14 int tfd;
15 DIR *sdir;
16 struct dirent *dirent;
18 if (argc != 3) {
19 fprintf(stderr, "Usage: %s SRC DST\n", argv[0]);
20 exit(1);
23 sdir = opendir(argv[1]);
24 if (sdir == NULL) {
25 fprintf(stderr, "Failed to open %s: %s\n",
26 argv[1], strerror(errno));
27 exit(2);
30 tfd = open(argv[2], O_DIRECTORY);
31 if (tfd < 0) {
32 fprintf(stderr, "Failed to open %s: %s\n",
33 argv[2], strerror(errno));
34 closedir(sdir);
35 exit(3);
38 while ((dirent = readdir(sdir)) != NULL) {
39 if (dirent->d_name[0] == '.' &&
40 (dirent->d_name[1] == '.' || dirent->d_name[1] == '\0'))
41 continue;
43 int fd = openat(tfd, dirent->d_name, O_CREAT|O_WRONLY, 0666);
44 if (fd < 0) {
45 fprintf(stderr, "Failed to create %s/%s: %s\n",
46 argv[2], dirent->d_name, strerror(errno));
47 closedir(sdir);
48 close(tfd);
49 exit(4);
51 close(fd);
54 closedir(sdir);
55 close(tfd);
57 return (0);