16int glob_sendfile_join(
const char *dest,
const char *pattern,
int perm, std::vector<std::string>& merged)
20 int err = glob(pattern, GLOB_NOSORT|GLOB_TILDE, NULL, &glob_results);
25 globfree(&glob_results);
28 globfree(&glob_results);
31 globfree(&glob_results);
35 int dest_fd = open(dest, O_WRONLY | O_CREAT |O_CLOEXEC | O_TRUNC , perm);
37 globfree(&glob_results);
41 for (
size_t i = 0; i < glob_results.gl_pathc; i++) {
42 int src_fd = open(glob_results.gl_pathv[i], O_RDONLY);
43 if (src_fd == -1)
continue;
46 if (fstat(src_fd, &stat_buf) == 0 && S_ISREG(stat_buf.st_mode)) {
48 size_t remaining = stat_buf.st_size;
51 while (remaining > 0) {
52 ssize_t sent = sendfile(dest_fd, src_fd, &offset, remaining);
56 if (sent == -1 && errno == EINTR)
continue;
63 merged.push_back(glob_results.gl_pathv[i]);
67 globfree(&glob_results);
int glob_sendfile_join(const char *dest, const char *pattern, int perm, std::vector< std::string > &merged)
use sendfile to join all files matching pattern in new dest file.