|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH 4/4] lib/nolibc: adapt sscanf code for Unikraft
1) Use the right includes
2) (u_)quad_t => (u)int64_t
3) u_char => unsigned char
4) strto(u)q => strto(u)ll
5) bcopy => memmove
6) fix warnings generated by modern gcc (8.1.1)
Signed-off-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx>
---
lib/nolibc/Makefile.uk | 1 +
lib/nolibc/include/stdio.h | 3 ++
lib/nolibc/sscanf.c | 64 ++++++++++++++++----------------------
lib/nolibc/stdio.c | 1 +
4 files changed, 32 insertions(+), 37 deletions(-)
diff --git a/lib/nolibc/Makefile.uk b/lib/nolibc/Makefile.uk
index 9186783..e7fd83d 100644
--- a/lib/nolibc/Makefile.uk
+++ b/lib/nolibc/Makefile.uk
@@ -26,6 +26,7 @@ LIBNOLIBC_SRCS-y += $(LIBNOLIBC_BASE)/ctype.c
LIBNOLIBC_SRCS-y += $(LIBNOLIBC_BASE)/stdlib.c
LIBNOLIBC_SRCS-y += $(LIBNOLIBC_BASE)/string.c
LIBNOLIBC_SRCS-y += $(LIBNOLIBC_BASE)/getopt.c
+LIBNOLIBC_SRCS-y += $(LIBNOLIBC_BASE)/sscanf.c
LIBNOLIBC_SRCS-$(CONFIG_LIBUKALLOC) += $(LIBNOLIBC_BASE)/malloc.c
# Localize internal symbols (starting with __*)
diff --git a/lib/nolibc/include/stdio.h b/lib/nolibc/include/stdio.h
index 073b132..6d5652f 100644
--- a/lib/nolibc/include/stdio.h
+++ b/lib/nolibc/include/stdio.h
@@ -64,6 +64,9 @@ int fflush(FILE *fp);
int vprintf(const char *fmt, va_list ap);
int printf(const char *fmt, ...) __printf(1, 2);
+int vsscanf(const char *str, const char *fmt, va_list ap);
+int sscanf(const char *str, const char *fmt, ...) __scanf(2, 3);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/nolibc/sscanf.c b/lib/nolibc/sscanf.c
index 5e016fa..e91c329 100644
--- a/lib/nolibc/sscanf.c
+++ b/lib/nolibc/sscanf.c
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -28,25 +29,14 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * From: Id: vfscanf.c,v 1.13 1998/09/25 12:20:27 obrien Exp
- * From: static char sccsid[] = "@(#)strtol.c 8.1 (Berkeley) 6/4/93";
- * From: static char sccsid[] = "@(#)strtoul.c 8.1 (Berkeley) 6/4/93";
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/ctype.h>
-#include <sys/limits.h>
-
-/*
- * Note that stdarg.h and the ANSI style va_start macro is used for both
- * ANSI and traditional C compilers.
- */
-#include <machine/stdarg.h>
+#include <stdarg.h>
+#include <sys/types.h>
+#include <stdint.h>
+#include <string.h>
+#include <ctype.h>
+#include <stdlib.h>
#define BUF 32 /* Maximum length of numeric string. */
@@ -81,8 +71,8 @@ __FBSDID("$FreeBSD$");
#define CT_CHAR 0 /* %c conversion */
#define CT_CCL 1 /* %[...] conversion */
#define CT_STRING 2 /* %s conversion */
-#define CT_INT 3 /* integer, i.e., strtoq or strtouq */
-typedef u_quad_t (*ccfntype)(const char *, char **, int);
+#define CT_INT 3 /* integer, i.e., strtoll or strtoull */
+typedef uint64_t (*ccfntype)(const char *, char **, int);
/*
* Fill in the given table from the scanset at the given format
@@ -90,8 +80,8 @@ typedef u_quad_t (*ccfntype)(const char *, char **, int);
* closing `]'. The table has a 1 wherever characters should be
* considered part of the scanset.
*/
-static const u_char *
-__sccl(char *tab, const u_char *fmt)
+static const unsigned char *
+__sccl(char *tab, const unsigned char *fmt)
{
int c, n, v;
@@ -180,7 +170,7 @@ int
vsscanf(const char *inp, char const *fmt0, va_list ap)
{
int inr;
- const u_char *fmt = (const u_char *)fmt0;
+ const unsigned char *fmt = (const unsigned char *)fmt0;
int c; /* character from format, or conversion */
size_t width; /* field width, or 0 */
char *p; /* points into all kinds of strings */
@@ -190,8 +180,8 @@ vsscanf(const char *inp, char const *fmt0, va_list ap)
int nassigned; /* number of fields assigned */
int nconversions; /* number of conversions */
int nread; /* number of characters consumed from fp */
- int base; /* base argument to strtoq/strtouq */
- ccfntype ccfn; /* conversion function (strtoq/strtouq) */
+ int base; /* base argument to strtoll/strtoull */
+ ccfntype ccfn; /* conversion function (strtoll/strtoull) */
char ccltab[256]; /* character class table for %[...] */
char buf[BUF]; /* buffer for numeric conversions */
@@ -271,32 +261,32 @@ literal:
*/
case 'd':
c = CT_INT;
- ccfn = (ccfntype)strtoq;
+ ccfn = (ccfntype)strtoll;
base = 10;
break;
case 'i':
c = CT_INT;
- ccfn = (ccfntype)strtoq;
+ ccfn = (ccfntype)strtoll;
base = 0;
break;
case 'o':
c = CT_INT;
- ccfn = strtouq;
+ ccfn = (ccfntype) strtoull;
base = 8;
break;
case 'u':
c = CT_INT;
- ccfn = strtouq;
+ ccfn = (ccfntype) strtoull;
base = 10;
break;
case 'x':
flags |= PFXOK; /* enable 0x prefixing */
c = CT_INT;
- ccfn = strtouq;
+ ccfn = (ccfntype) strtoull;
base = 16;
break;
@@ -318,7 +308,7 @@ literal:
case 'p': /* pointer format is like hex */
flags |= POINTER | PFXOK;
c = CT_INT;
- ccfn = strtouq;
+ ccfn = (ccfntype) strtoull;
base = 16;
break;
@@ -333,7 +323,7 @@ literal:
else if (flags & LONG)
*va_arg(ap, long *) = nread;
else if (flags & QUAD)
- *va_arg(ap, quad_t *) = nread;
+ *va_arg(ap, int64_t *) = nread;
else
*va_arg(ap, int *) = nread;
continue;
@@ -377,7 +367,7 @@ literal:
size_t sum = 0;
for (;;) {
- if ((n = inr) < width) {
+ if ((n = inr) < (int) width) {
sum += n;
width -= n;
inp += n;
@@ -393,7 +383,7 @@ literal:
}
nread += sum;
} else {
- bcopy(inp, va_arg(ap, char *), width);
+ memmove(va_arg(ap, char *), inp, width);
inr -= width;
inp += width;
nread += width;
@@ -476,7 +466,7 @@ literal:
continue;
case CT_INT:
- /* scan an integer as if by strtoq/strtouq */
+ /* scan an integer as if by strtoll/strtoull */
#ifdef hardway
if (width == 0 || width > sizeof(buf) - 1)
width = sizeof(buf) - 1;
@@ -594,14 +584,14 @@ ok:
}
goto match_failure;
}
- c = ((u_char *)p)[-1];
+ c = ((unsigned char *)p)[-1];
if (c == 'x' || c == 'X') {
--p;
inp--;
inr++;
}
if ((flags & SUPPRESS) == 0) {
- u_quad_t res;
+ uint64_t res;
*p = 0;
res = (*ccfn)(buf, (char **)NULL, base);
@@ -615,7 +605,7 @@ ok:
else if (flags & LONG)
*va_arg(ap, long *) = res;
else if (flags & QUAD)
- *va_arg(ap, quad_t *) = res;
+ *va_arg(ap, int64_t *) = res;
else
*va_arg(ap, int *) = res;
nassigned++;
diff --git a/lib/nolibc/stdio.c b/lib/nolibc/stdio.c
index 7e3d368..3a32907 100644
--- a/lib/nolibc/stdio.c
+++ b/lib/nolibc/stdio.c
@@ -289,6 +289,7 @@ reswitch:
goto handle_nosign;
case 'X':
upper = 1;
+ /* Fall through */
case 'x':
base = 16;
goto handle_nosign;
--
2.17.1
_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |