added "syslog facility" option. It is an integer and defaults to the
[rsync/rsync.git] / util.c
diff --git a/util.c b/util.c
index 59f9418..346d58a 100644 (file)
--- a/util.c
+++ b/util.c
@@ -446,58 +446,40 @@ void kill_all(int sig)
        }
 }
 
-/* this is the rsync debugging function. Call it with FINFO or FERROR */
-void rprintf(int fd, const char *format, ...)
+/* like strncpy but does not 0 fill the buffer and always null 
+   terminates (thus it can use maxlen+1 space in d) */
+void strlcpy(char *d, char *s, int maxlen)
 {
-       va_list ap;  
-       char buf[1024];
-       int len;
-       FILE *f=NULL;
-
-       va_start(ap, format);
-
-#if HAVE_VSNPRINTF
-       len = vsnprintf(buf, sizeof(buf)-1, format, ap);
-#else
-       len = vsprintf(buf, format, ap);
-#endif
-       va_end(ap);
-
-       if (len < 0) exit_cleanup(1);
-
-       if (fd == FERROR) {
-               f = stderr;
-       } 
-
-       if (fd == FINFO) {
-               extern int am_server;
-               if (am_server) 
-                       f = stderr;
-               else
-                       f = stdout;
-       } 
-
-       if (!f) exit_cleanup(1);
+       int len = strlen(s);
+       if (len > maxlen) len = maxlen;
+       memcpy(d, s, len);
+       d[len] = 0;
+}
 
-       if (fwrite(buf, len, 1, f) != 1) exit_cleanup(1);
+/* turn a user name into a uid */
+int name_to_uid(char *name, uid_t *uid)
+{
+       struct passwd *pass;
+       if (!name || !*name) return 0;
+       pass = getpwnam(name);
+       if (pass) {
+               *uid = pass->pw_uid;
+               return 1;
+       }
+       return 0;
 }
 
-void rflush(int fd)
+/* turn a group name into a gid */
+int name_to_gid(char *name, gid_t *gid)
 {
-       FILE *f = NULL;
+       struct group *grp;
+       if (!name || !*name) return 0;
+       grp = getgrnam(name);
+       if (grp) {
+               *gid = grp->gr_gid;
+               return 1;
+       }
+       return 0;
+}
 
-       if (fd == FERROR) {
-               f = stderr;
-       } 
 
-       if (fd == FINFO) {
-               extern int am_server;
-               if (am_server) 
-                       f = stderr;
-               else
-                       f = stdout;
-       } 
-
-       if (!f) exit_cleanup(1);
-       fflush(f);
-}