X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/5243c216d6db4c728c7bf0ad7ab769c9bb6a728b..067857e0acaaceae0737b38c576aacea37e84eb8:/util.c diff --git a/util.c b/util.c index 11e4a9d9..34c8f8b0 100644 --- a/util.c +++ b/util.c @@ -24,15 +24,33 @@ */ #include "rsync.h" -int num_waiting(int fd) +/**************************************************************************** +Set a fd into nonblocking mode. Uses POSIX O_NONBLOCK if available, +else +if SYSV use O_NDELAY +if BSD use FNDELAY +****************************************************************************/ +int set_nonblocking(int fd) { - int len=0; - ioctl(fd,FIONREAD,&len); - return(len); + int val; +#ifdef O_NONBLOCK +#define FLAG_TO_SET O_NONBLOCK +#else +#ifdef SYSV +#define FLAG_TO_SET O_NDELAY +#else /* BSD */ +#define FLAG_TO_SET FNDELAY +#endif +#endif + + if((val = fcntl(fd, F_GETFL, 0)) == -1) + return -1; + val |= FLAG_TO_SET; + return fcntl( fd, F_SETFL, val); +#undef FLAG_TO_SET } - /* this is taken from CVS */ int piped_child(char **command,int *f_in,int *f_out) { @@ -206,7 +224,7 @@ int create_directory_path(char *fname) derived from GNU C's cccp.c. */ -int full_write(int desc, char *ptr, int len) +static int full_write(int desc, char *ptr, int len) { int total_written; @@ -653,3 +671,42 @@ int pop_dir(char *dir) return 0; } + +/* we need to supply our own strcmp function for file list comparisons + to ensure that signed/unsigned usage is consistent between machines. */ +int u_strcmp(const char *cs1, const char *cs2) +{ + const uchar *s1 = (uchar *)cs1; + const uchar *s2 = (uchar *)cs2; + + while (*s1 && *s2 && (*s1 == *s2)) { + s1++; s2++; + } + + return (int)*s1 - (int)*s2; +} + +static int last_pct = -1; + +void end_progress(void) +{ + extern int do_progress, am_server; + + if (do_progress && !am_server) { + rprintf(FINFO,"\n"); + } + last_pct = -1; +} + +void show_progress(OFF_T ofs, OFF_T size) +{ + extern int do_progress, am_server; + + if (do_progress && !am_server) { + int pct = (int)((100.0*ofs)/size + 0.5); + if (pct != last_pct) { + rprintf(FINFO,"%.0f (%d%%)\r", (double)ofs, pct); + last_pct = pct; + } + } +}