Module Name:    src
Committed By:   christos
Date:           Tue Oct 18 17:56:31 UTC 2016

Modified Files:
        src/lib/libperfuse: fuse.h perfuse.c perfuse_if.h

Log Message:
make this compile again, and simplify.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libperfuse/fuse.h
cvs rdiff -u -r1.38 -r1.39 src/lib/libperfuse/perfuse.c
cvs rdiff -u -r1.20 -r1.21 src/lib/libperfuse/perfuse_if.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libperfuse/fuse.h
diff -u src/lib/libperfuse/fuse.h:1.6 src/lib/libperfuse/fuse.h:1.7
--- src/lib/libperfuse/fuse.h:1.6	Fri Oct 31 11:12:15 2014
+++ src/lib/libperfuse/fuse.h	Tue Oct 18 13:56:31 2016
@@ -1,4 +1,4 @@
-/*  $NetBSD: fuse.h,v 1.6 2014/10/31 15:12:15 manu Exp $ */
+/*  $NetBSD: fuse.h,v 1.7 2016/10/18 17:56:31 christos Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -34,8 +34,8 @@
 #define FUSE_UNKNOWN_FH (uint64_t)0
 
 #ifndef FUSE_BUFSIZE
-#define FUSE_MIN_BUFSIZE 0x21000
-#define FUSE_PREF_BUFSIZE (sysconf(_SC_PAGESIZE) + 0x1000)
+#define FUSE_MIN_BUFSIZE ((size_t)0x21000)
+#define FUSE_PREF_BUFSIZE ((size_t)(sysconf(_SC_PAGESIZE) + 0x1000))
 #define FUSE_BUFSIZE MAX(FUSE_PREF_BUFSIZE /* CONSTCOND */, FUSE_MIN_BUFSIZE)
 #endif /* FUSE_BUFSIZE */
 

Index: src/lib/libperfuse/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.38 src/lib/libperfuse/perfuse.c:1.39
--- src/lib/libperfuse/perfuse.c:1.38	Tue Oct 18 11:06:17 2016
+++ src/lib/libperfuse/perfuse.c	Tue Oct 18 13:56:31 2016
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.38 2016/10/18 15:06:17 manu Exp $ */
+/*  $NetBSD: perfuse.c,v 1.39 2016/10/18 17:56:31 christos Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -32,6 +32,7 @@
 #include <string.h>
 #include <errno.h>
 #include <puffs.h>
+#include <inttypes.h>
 #include <sys/types.h>
 #include <sys/mman.h>
 #include <sys/resource.h>
@@ -51,7 +52,7 @@ extern char **environ;
 
 static struct perfuse_state *init_state(void);
 static int get_fd(const char *);
-static uint32_t bufvar_from_env(const char *, const uint32_t);
+static uint32_t bufvar_from_env(const char *, uint32_t);
 
 
 static struct perfuse_state *
@@ -148,32 +149,22 @@ get_fd(const char *data)
 }
 
 static uint32_t 
-bufvar_from_env(name, defval)
-	const char *name;
-	const uint32_t defval;
+bufvar_from_env(const char *name, uint32_t defval)
 {
 	char valstr[1024];
-	uint32_t retval = defval;
+	int e;
+	uint32_t retval;
 
-	if (getenv_r(name, valstr, sizeof(valstr)) != -1) {
-		long int val;
-		char *ep;
-
-		errno = 0;
-		val = (int)strtol(valstr, &ep, 10);
-		if (*valstr == '\0' || *ep != '\0')
-			DWARNX("bad %s value \"%s\"", name, valstr);
-		else if (errno != 0)
-			DWARN("bad %s value \"%s\"", name, valstr);
-		else if (val <= 0L ||
-			 (unsigned long int)val > (unsigned long int)UINT32_MAX)
-			DWARNX("%s value %ld out of "
-			       "uint32_t bounds", name, val);
-		else
-			retval = val;
-	}
+	if (getenv_r(name, valstr, sizeof(valstr)) == -1)
+		return defval;
 
-	return retval;
+	retval = (uint32_t)strtoi(valstr, NULL, 0, 0, UINT32_MAX, &e);
+	if (!e)
+		return retval;
+
+	DWARNC(e, "conversion from `%s' to uint32_t failed, using %u",
+	    valstr, defval);
+	return defval;
 }
 
 int
@@ -213,7 +204,7 @@ perfuse_open(const char *path, int flags
 	 * Set a buffer lentgh large enough so that enough FUSE packets
 	 * will fit.
 	 */
-	opt = bufvar_from_env("PERFUSE_BUFSIZE", 16 * FUSE_BUFSIZE);
+	opt = bufvar_from_env("PERFUSE_BUFSIZE", (uint32_t)(16 * FUSE_BUFSIZE));
 	optlen = sizeof(opt);
 	if (setsockopt(sv[0], SOL_SOCKET, SO_SNDBUF, &opt, optlen) != 0)
 		DWARN("%s: setsockopt SO_SNDBUF to %d failed", __func__, opt);
@@ -244,7 +235,7 @@ perfuse_open(const char *path, int flags
 	 * Set a buffer lentgh large enough so that enough FUSE packets
 	 * will fit.
 	 */
-	opt = bufvar_from_env("PERFUSE_BUFSIZE", 16 * FUSE_BUFSIZE);
+	opt = bufvar_from_env("PERFUSE_BUFSIZE", (uint32_t)(16 * FUSE_BUFSIZE));
 	optlen = sizeof(opt);
 	if (setsockopt(sv[0], SOL_SOCKET, SO_SNDBUF, &opt, optlen) != 0)
 		DWARN("%s: setsockopt SO_SNDBUF to %d failed", __func__, opt);

Index: src/lib/libperfuse/perfuse_if.h
diff -u src/lib/libperfuse/perfuse_if.h:1.20 src/lib/libperfuse/perfuse_if.h:1.21
--- src/lib/libperfuse/perfuse_if.h:1.20	Sat Jul 21 01:49:42 2012
+++ src/lib/libperfuse/perfuse_if.h	Tue Oct 18 13:56:31 2016
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_if.h,v 1.20 2012/07/21 05:49:42 manu Exp $ */
+/*  $NetBSD: perfuse_if.h,v 1.21 2016/10/18 17:56:31 christos Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -103,13 +103,20 @@ extern int perfuse_diagflags;
 } while (0 /* CONSTCOND */)
 
 #define DWARN(fmt, ...) do {						\
-									\
 	if (perfuse_diagflags & PDF_SYSLOG) 				\
 		syslog(LOG_WARNING, fmt ": %m", ## __VA_ARGS__);	\
 									\
 	warn(fmt, ## __VA_ARGS__);					\
 } while (0 /* CONSTCOND */)
 
+#define DWARNC(e, fmt, ...) do {					\
+	if (perfuse_diagflags & PDF_SYSLOG) { 				\
+		errno = e;						\
+		syslog(LOG_WARNING, fmt ": %m", ## __VA_ARGS__);	\
+	}								\
+	warnc(e, fmt, ## __VA_ARGS__);					\
+} while (0 /* CONSTCOND */)
+
 /*
  * frame handling callbacks
  */

Reply via email to