diff options
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 18 |
1 files changed, 8 insertions, 10 deletions
@@ -125,9 +125,8 @@ void rotdash_hide(void) { const char* get_attached_filename(const char *root, const char *fn) { static char npath[PATH_MAX]; - snprintf(npath, sizeof(npath), "%s/.syrep", root); - mkdir(npath, 0777); snprintf(npath, sizeof(npath), "%s/.syrep/%s", root, fn); + makeprefixpath(npath, 0777); return npath; } @@ -164,7 +163,7 @@ int isdirectory(const char *path) { #ifdef USE_SENDFILE -#define MAX_SENDFILE_SIZE (1024*1024*1024) /* A gigabyte */ +#define MAX_SENDFILE_SIZE (1024L*1024L*1024L) /* A gigabyte */ static int copy_fd_sendfile(int sfd, int dfd, off_t l) { off_t sfo, o; @@ -195,7 +194,6 @@ static int copy_fd_sendfile(int sfd, int dfd, off_t l) { #endif - off_t filesize(int fd) { struct stat st; @@ -210,10 +208,10 @@ off_t filesize(int fd) { int expand_file(int fd, off_t l) { off_t s; - if ((s = filesize(fd)) < 0) + if ((s = filesize(fd)) == (off_t) -1) return -1; - if (s < l) + if (l > s) if (ftruncate(fd, l) < 0) { fprintf(stderr, "ftruncate(): %s\n", strerror(errno)); return -1; @@ -222,8 +220,8 @@ int expand_file(int fd, off_t l) { return 0; } -#define MMAPSIZE (100*1024*1024) /* 100MB */ -#define BUFSIZE (32*1024) +#define MMAPSIZE (20*1024*1024) /* 20MB */ +#define BUFSIZE (64*1024) int copy_fd(int sfd, int dfd, off_t l) { off_t sfo = 0, dfo = 0, msfo = 0, mdfo = 0; @@ -232,7 +230,7 @@ int copy_fd(int sfd, int dfd, off_t l) { static size_t psize = 0; #ifdef USE_SENDFILE - if (copy_fd_sendfile(sfd, dfd, l) == 0) + if (copy_fd_sendfile(sfd, dfd, l) >= 0) return 0; if (errno == ENOSPC) @@ -258,7 +256,7 @@ int copy_fd(int sfd, int dfd, off_t l) { if ((s = filesize(sfd)) < 0) return -1; - if (s < sfo+l) { + if (sfo+l > s) { fprintf(stderr, "File too short\n"); return -1; } |