removed a debug line
[rsync/rsync.git] / util.c
diff --git a/util.c b/util.c
index 67308cd..ffbdc93 100644 (file)
--- a/util.c
+++ b/util.c
@@ -482,3 +482,52 @@ int name_to_gid(char *name, gid_t *gid)
        return 0;
 }
 
+
+/****************************************************************************
+check if a process exists. 
+****************************************************************************/
+int process_exists(int pid)
+{
+       return(kill(pid,0) == 0 || errno != ESRCH);
+}
+
+/* lock a byte range in a open file */
+int lock_range(int fd, int offset, int len)
+{
+       struct flock lock;
+
+       lock.l_type = F_WRLCK;
+       lock.l_whence = SEEK_SET;
+       lock.l_start = offset;
+       lock.l_len = len;
+       lock.l_pid = 0;
+       
+       return fcntl(fd,F_SETLK,&lock) == 0;
+}
+
+
+void glob_expand(char **argv, int *argc, int maxargs)
+{
+#ifndef HAVE_GLOB
+       (*argc)++;
+       return;
+#else
+       glob_t globbuf;
+       int i;
+
+       memset(&globbuf, 0, sizeof(globbuf));
+       glob(argv[*argc], 0, NULL, &globbuf);
+       if (globbuf.gl_pathc == 0) {
+               (*argc)++;
+               globfree(&globbuf);
+               return;
+       }
+       for (i=0; i<(maxargs - (*argc)) && i<globbuf.gl_pathc;i++) {
+               if (i == 0) free(argv[*argc]);
+               argv[(*argc) + i] = strdup(globbuf.gl_pathv[i]);
+               if (!argv[(*argc) + i]) out_of_memory("glob_expand");
+       }
+       globfree(&globbuf);
+       (*argc) += i;
+#endif
+}