update Debian standards version
[debian/sudo] / fileops.c
index e15c512788836cd68f544546145dda265398924e..40cc86023a453c5eff07302687a203f10a305dad 100644 (file)
--- a/fileops.c
+++ b/fileops.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999-2005 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 1999-2005,2007,2009 Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
 # include <sys/file.h>
 #endif /* HAVE_FLOCK */
 #include <stdio.h>
+#ifdef HAVE_STRING_H
+# include <string.h>
+#else
+# ifdef HAVE_STRINGS_H
+#  include <strings.h>
+# endif
+#endif /* HAVE_STRING_H */
+#include <ctype.h>
+#include <limits.h>
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif /* HAVE_UNISTD_H */
 
 #include "sudo.h"
 
+#ifndef LINE_MAX
+# define LINE_MAX 2048
+#endif
+
 #ifndef lint
-__unused static const char rcsid[] = "$Sudo: fileops.c,v 1.5.2.5 2007/06/12 01:28:41 millert Exp $";
+__unused static const char rcsid[] = "$Sudo: fileops.c,v 1.19 2009/05/25 12:02:41 millert Exp $";
 #endif /* lint */
 
 /*
@@ -131,7 +144,7 @@ lock_file(fd, lockit)
     lock.l_pid = getpid();
     lock.l_type = (lockit == SUDO_UNLOCK) ? F_UNLCK : F_WRLCK;
     lock.l_whence = SEEK_SET;
-    func = (lockit == SUDO_TLOCK) ? F_SETLK : F_SETLKW;
+    func = (lockit == SUDO_LOCK) ? F_SETLKW : F_SETLK;
 
     return(fcntl(fd, func, &lock) == 0);
 #else
@@ -139,3 +152,30 @@ lock_file(fd, lockit)
 #endif
 }
 #endif
+
+/*
+ * Read a line of input, remove comments and strip off leading
+ * and trailing spaces.  Returns static storage that is reused.
+ */
+char *
+sudo_parseln(fp)
+    FILE *fp;
+{
+    size_t len;
+    char *cp = NULL;
+    static char buf[LINE_MAX];
+
+    if (fgets(buf, sizeof(buf), fp) != NULL) {
+       /* Remove comments */
+       if ((cp = strchr(buf, '#')) != NULL)
+           *cp = '\0';
+
+       /* Trim leading and trailing whitespace/newline */
+       len = strlen(buf);
+       while (len > 0 && isspace((unsigned char)buf[len - 1]))
+           buf[--len] = '\0';
+       for (cp = buf; isblank(*cp); cp++)
+           continue;
+    }
+    return(cp);
+}