[Midnightbsd-cvs] src [10501] trunk/lib/libutil: sync

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Wed Jun 6 21:43:04 EDT 2018


Revision: 10501
          http://svnweb.midnightbsd.org/src/?rev=10501
Author:   laffer1
Date:     2018-06-06 21:43:03 -0400 (Wed, 06 Jun 2018)
Log Message:
-----------
sync

Modified Paths:
--------------
    trunk/lib/libutil/expand_number.c
    trunk/lib/libutil/flopen.c
    trunk/lib/libutil/fparseln.c

Modified: trunk/lib/libutil/expand_number.c
===================================================================
--- trunk/lib/libutil/expand_number.c	2018-06-07 01:40:33 UTC (rev 10500)
+++ trunk/lib/libutil/expand_number.c	2018-06-07 01:43:03 UTC (rev 10501)
@@ -35,31 +35,24 @@
 #include <libutil.h>
 #include <stdint.h>
 
-/*
- * Convert an expression of the following forms to a uint64_t.
- *	1) A positive decimal number.
- *	2) A positive decimal number followed by a 'b' or 'B' (mult by 1).
- *	3) A positive decimal number followed by a 'k' or 'K' (mult by 1 << 10).
- *	4) A positive decimal number followed by a 'm' or 'M' (mult by 1 << 20).
- *	5) A positive decimal number followed by a 'g' or 'G' (mult by 1 << 30).
- *	6) A positive decimal number followed by a 't' or 'T' (mult by 1 << 40).
- *	7) A positive decimal number followed by a 'p' or 'P' (mult by 1 << 50).
- *	8) A positive decimal number followed by a 'e' or 'E' (mult by 1 << 60).
- */
 int
 expand_number(const char *buf, uint64_t *num)
 {
+	char *endptr;
+	uintmax_t umaxval;
 	uint64_t number;
 	unsigned shift;
-	char *endptr;
+	int serrno;
 
-	number = strtoumax(buf, &endptr, 0);
-
-	if (endptr == buf) {
-		/* No valid digits. */
-		errno = EINVAL;
+	serrno = errno;
+	errno = 0;
+	umaxval = strtoumax(buf, &endptr, 0);
+	if (umaxval > UINT64_MAX)
+		errno = ERANGE;
+	if (errno != 0)
 		return (-1);
-	}
+	errno = serrno;
+	number = umaxval;
 
 	switch (tolower((unsigned char)*endptr)) {
 	case 'e':
@@ -95,7 +88,6 @@
 		errno = ERANGE;
 		return (-1);
 	}
-
 	*num = number << shift;
 	return (0);
 }

Modified: trunk/lib/libutil/flopen.c
===================================================================
--- trunk/lib/libutil/flopen.c	2018-06-07 01:40:33 UTC (rev 10500)
+++ trunk/lib/libutil/flopen.c	2018-06-07 01:43:03 UTC (rev 10501)
@@ -26,7 +26,6 @@
  */
 
 #include <sys/cdefs.h>
-/* $FreeBSD: src/lib/libutil/flopen.c,v 1.9.4.1 2009/06/09 01:43:58 des Exp $ */
 __MBSDID("$MidnightBSD$");
 
 #include <sys/file.h>
@@ -41,16 +40,16 @@
 int
 flopen(const char *path, int flags, ...)
 {
-	int fd, operation, serrno, trunc, flags2;
+	int fd, operation, serrno, trunc;
 	struct stat sb, fsb;
-	mode_t mode = 0;
+	mode_t mode;
 
-/* this is an ugly hack to work around va_args second arg bug with GCC */
-	flags2 = flags;
 #ifdef O_EXLOCK
-	flags2 &= ~O_EXLOCK;
+	flags &= ~O_EXLOCK;
 #endif
-	if (flags2 & O_CREAT) {
+
+	mode = 0;
+	if (flags & O_CREAT) {
 		va_list ap;
 
 		va_start(ap, flags);
@@ -57,9 +56,6 @@
 		mode = (mode_t)va_arg(ap, int); /* mode_t promoted to int */
 		va_end(ap);
 	}
-#ifdef O_EXLOCK
-	flags = flags2;
-#endif
 
         operation = LOCK_EX;
         if (flags & O_NONBLOCK)

Modified: trunk/lib/libutil/fparseln.c
===================================================================
--- trunk/lib/libutil/fparseln.c	2018-06-07 01:40:33 UTC (rev 10500)
+++ trunk/lib/libutil/fparseln.c	2018-06-07 01:43:03 UTC (rev 10501)
@@ -1,4 +1,4 @@
-/*	$NetBSD: fparseln.c,v 1.9 1999/09/20 04:48:06 lukem Exp $	*/
+/*	$NetBSD: fparseln.c,v 1.7 2007/03/08 19:57:53 drochner Exp $	*/
 
 /*
  * Copyright (c) 1997 Christos Zoulas.  All rights reserved.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$FreeBSD: src/lib/libutil/fparseln.c,v 1.6 2003/10/18 10:04:16 markm Exp $");
+__MBSDID("$MidnightBSD$");
 
 #include <sys/types.h>
 #include <assert.h>
@@ -59,7 +59,7 @@
 
 	/* No escape character */
 	if (esc == '\0')
-		return 1;
+		return 0;
 
 	/* Count the number of escape characters that precede ours */
 	for (ne = 0, cp = p; --cp >= sp && *cp == esc; ne++)
@@ -135,13 +135,19 @@
 			cp = &ptr[s - 1];
 
 			if (*cp == con && !isescaped(ptr, cp, esc)) {
-				s--;	/* forget escape */
+				s--;	/* forget continuation char */
 				cnt = 1;
 			}
 		}
 
-		if (s == 0 && buf != NULL)
-			continue;
+		if (s == 0) {
+			/*
+			 * nothing to add, skip realloc except in case
+			 * we need a minimal buf to return an empty line
+			 */
+			if (cnt || buf != NULL)
+				continue;
+		}
 
 		if ((cp = realloc(buf, len + s + 1)) == NULL) {
 			free(buf);



More information about the Midnightbsd-cvs mailing list