X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/773f2bd47f48b737cef2852341b86f5d086a5fef..684b4e31132b2b8df6b4feddeb006239b989793c:/util.c diff --git a/util.c b/util.c index 4301465e..e53d02a0 100644 --- a/util.c +++ b/util.c @@ -55,6 +55,8 @@ struct map_struct *map_file(int fd,off_t len) char *map_ptr(struct map_struct *map,off_t offset,int len) { + int nread = -2; + if (map->map) return map->map+offset; @@ -79,8 +81,9 @@ char *map_ptr(struct map_struct *map,off_t offset,int len) } if (lseek(map->fd,offset,SEEK_SET) != offset || - read(map->fd,map->p,len) != len) { - fprintf(FERROR,"EOF in map_ptr!\n"); + (nread=read(map->fd,map->p,len)) != len) { + fprintf(FERROR,"EOF in map_ptr! (offset=%d len=%d nread=%d errno=%d)\n", + (int)offset, len, nread, errno); exit_cleanup(1); } @@ -124,6 +127,7 @@ int piped_child(char **command,int *f_in,int *f_out) if (pid == 0) { + extern int orig_umask; if (dup2(to_child_pipe[0], STDIN_FILENO) < 0 || close(to_child_pipe[1]) < 0 || close(from_child_pipe[0]) < 0 || @@ -133,6 +137,7 @@ int piped_child(char **command,int *f_in,int *f_out) } if (to_child_pipe[0] != STDIN_FILENO) close(to_child_pipe[0]); if (from_child_pipe[1] != STDOUT_FILENO) close(from_child_pipe[1]); + umask(orig_umask); execvp(command[0], command); fprintf(FERROR,"Failed to exec %s : %s\n", command[0],strerror(errno)); @@ -223,3 +228,26 @@ int set_blocking(int fd, int set) return fcntl( fd, F_SETFL, val); #undef FLAG_TO_SET } + +/**************************************************************************** +create any necessary directories in fname. Unfortunately we don't know +what perms to give the directory when this is called so we need to rely +on the umask +****************************************************************************/ +int create_directory_path(char *fname) +{ + extern int orig_umask; + char *p; + + while (*fname == '/') fname++; + while (strncmp(fname,"./",2)==0) fname += 2; + + p = fname; + while ((p=strchr(p,'/'))) { + *p = 0; + mkdir(fname,0777 & ~orig_umask); + *p = '/'; + p++; + } + return 0; +}