X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/89d26123ff63a788e9cb7d07df3538f9e5d536d1..bec617b934dc2ef90b7acd1c7ef4b5db74821e91:/util.c diff --git a/util.c b/util.c index cde75717..e99ede8e 100644 --- a/util.c +++ b/util.c @@ -120,7 +120,7 @@ void out_of_memory(char *str) exit_cleanup(RERR_MALLOC); } -void overflow(char *str) +void overflow_exit(char *str) { rprintf(FERROR, "ERROR: buffer overflow in %s\n", str); exit_cleanup(RERR_MALLOC); @@ -128,8 +128,13 @@ void overflow(char *str) -int set_modtime(char *fname, time_t modtime) +int set_modtime(char *fname, time_t modtime, mode_t mode) { +#if !defined HAVE_LUTIMES || !defined HAVE_UTIMES + if (S_ISLNK(mode)) + return 1; +#endif + if (verbose > 2) { rprintf(FINFO, "set modtime of %s to (%ld) %s", safe_fname(fname), (long)modtime, @@ -140,7 +145,18 @@ int set_modtime(char *fname, time_t modtime) return 0; { -#ifdef HAVE_UTIMBUF +#ifdef HAVE_UTIMES + struct timeval t[2]; + t[0].tv_sec = time(NULL); + t[0].tv_usec = 0; + t[1].tv_sec = modtime; + t[1].tv_usec = 0; +# ifdef HAVE_LUTIMES + if (S_ISLNK(mode)) + return lutimes(fname, t); +# endif + return utimes(fname, t); +#elif defined HAVE_UTIMBUF struct utimbuf tbuf; tbuf.actime = time(NULL); tbuf.modtime = modtime; @@ -151,12 +167,7 @@ int set_modtime(char *fname, time_t modtime) t[1] = modtime; return utime(fname,t); #else - struct timeval t[2]; - t[0].tv_sec = time(NULL); - t[0].tv_usec = 0; - t[1].tv_sec = modtime; - t[1].tv_usec = 0; - return utimes(fname,t); +#error No file-time-modification routine found! #endif } } @@ -892,7 +903,7 @@ char *safe_fname(const char *fname) char *t; ndx = (ndx + 1) % MAX_SAFE_NAMES; - for (t = fbuf[ndx]; *fname && limit; fname++) { + for (t = fbuf[ndx]; *fname; fname++) { if (*fname == '\\') { if ((limit -= 2) < 0) break; @@ -904,7 +915,8 @@ char *safe_fname(const char *fname) sprintf(t, "\\%03o", *(uchar*)fname); t += 4; } else { - limit--; + if (--limit < 0) + break; *t++ = *fname; } }