From 40d1ed7f0c9d8af6f4346af6582e8e0c2e9992a9 Mon Sep 17 00:00:00 2001 From: ian Date: Sun, 10 Jun 2018 22:26:15 +0000 Subject: [PATCH] MFC r334656, r334665, r334695 r334656: Add vsnprintf() to libsa. Alpha-sort the printf prototypes in stand.h. r334665: Make the v*printf() functions in libsa return int instead of void. This makes them compatible with the C standard signatures, avoiding spurious mismatch errors in the places where the oddball requirements of standalone code end up putting two declarations of the same function in play. r334695: Remove comments and assertions that are no longer valid after r330809. r330809 replaced duplication of devdesc struct fields with an embedded copy of the devdesc struct, to avoid fragility. That means all the scattered comments indicating that structs must match are no longer valid. Likewise asserts that attempted to mitigate some of the old fragility. Reviewed by: imp@ --- stand/common/disk.h | 3 +-- stand/i386/libi386/biosdisk.c | 2 -- stand/i386/libi386/libi386.h | 4 +--- stand/libsa/printf.c | 25 ++++++++++++++++++++++--- stand/libsa/stand.h | 5 +++-- stand/uboot/lib/libuboot.h | 3 +-- stand/userboot/userboot/main.c | 1 - stand/zfs/libzfs.h | 5 +---- 8 files changed, 29 insertions(+), 19 deletions(-) diff --git a/stand/common/disk.h b/stand/common/disk.h index 8396c2702a3..1e4543d09c9 100644 --- a/stand/common/disk.h +++ b/stand/common/disk.h @@ -81,9 +81,8 @@ #ifndef _DISK_H #define _DISK_H -/* Note: Must match the 'struct devdesc' in stand.h */ struct disk_devdesc { - struct devdesc dd; + struct devdesc dd; /* Must be first. */ int d_slice; int d_partition; uint64_t d_offset; diff --git a/stand/i386/libi386/biosdisk.c b/stand/i386/libi386/biosdisk.c index eb1f688e884..ead5dbd0cfc 100644 --- a/stand/i386/libi386/biosdisk.c +++ b/stand/i386/libi386/biosdisk.c @@ -78,8 +78,6 @@ struct ptable { #include "geliboot.c" #endif /* LOADER_GELI_SUPPORT */ -CTASSERT(sizeof(struct i386_devdesc) >= sizeof(struct disk_devdesc)); - #define BIOS_NUMDRIVES 0x475 #define BIOSDISK_SECSIZE 512 #define BUFSIZE (1 * BIOSDISK_SECSIZE) diff --git a/stand/i386/libi386/libi386.h b/stand/i386/libi386/libi386.h index da1ba4d6900..8fcb3e37a66 100644 --- a/stand/i386/libi386/libi386.h +++ b/stand/i386/libi386/libi386.h @@ -29,11 +29,9 @@ /* * i386 fully-qualified device descriptor. - * Note, this must match struct zfs_devdesc for zfs support. */ -/* Note: Must match the 'struct devdesc' in stand.h */ struct i386_devdesc { - struct devdesc dd; + struct devdesc dd; /* Must be first. */ union { struct diff --git a/stand/libsa/printf.c b/stand/libsa/printf.c index 71e313cc55a..9c75d33b92f 100644 --- a/stand/libsa/printf.c +++ b/stand/libsa/printf.c @@ -80,11 +80,11 @@ printf(const char *fmt, ...) return retval; } -void +int vprintf(const char *fmt, va_list ap) { - kvprintf(fmt, putchar_wrapper, NULL, 10, ap); + return (kvprintf(fmt, putchar_wrapper, NULL, 10, ap)); } int @@ -140,13 +140,32 @@ snprintf(char *buf, size_t size, const char *cfmt, ...) return retval; } -void +int +vsnprintf(char *buf, size_t size, const char *cfmt, va_list ap) +{ + struct print_buf arg; + int retval; + + arg.buf = buf; + arg.size = size; + + retval = kvprintf(cfmt, &snprint_func, &arg, 10, ap); + + if (arg.size >= 1) + *(arg.buf)++ = 0; + + return (retval); +} + +int vsprintf(char *buf, const char *cfmt, va_list ap) { int retval; retval = kvprintf(cfmt, NULL, (void *)buf, 10, ap); buf[retval] = '\0'; + + return (retval); } /* diff --git a/stand/libsa/stand.h b/stand/libsa/stand.h index aebf07a5e8c..816bd936f69 100644 --- a/stand/libsa/stand.h +++ b/stand/libsa/stand.h @@ -268,10 +268,11 @@ extern void *reallocf(void *ptr, size_t size); extern void mallocstats(void); extern int printf(const char *fmt, ...) __printflike(1, 2); -extern void vprintf(const char *fmt, __va_list); extern int sprintf(char *buf, const char *cfmt, ...) __printflike(2, 3); extern int snprintf(char *buf, size_t size, const char *cfmt, ...) __printflike(3, 4); -extern void vsprintf(char *buf, const char *cfmt, __va_list); +extern int vprintf(const char *fmt, __va_list); +extern int vsprintf(char *buf, const char *cfmt, __va_list); +extern int vsnprintf(char *buf, size_t size, const char *cfmt, __va_list); extern void twiddle(u_int callerdiv); extern void twiddle_divisor(u_int globaldiv); diff --git a/stand/uboot/lib/libuboot.h b/stand/uboot/lib/libuboot.h index 221f48f7878..8b81486b1fa 100644 --- a/stand/uboot/lib/libuboot.h +++ b/stand/uboot/lib/libuboot.h @@ -27,9 +27,8 @@ * $FreeBSD$ */ -/* Note: Must match the 'struct devdesc' in stand.h */ struct uboot_devdesc { - struct devdesc dd; + struct devdesc dd; /* Must be first. */ union { struct { int slice; diff --git a/stand/userboot/userboot/main.c b/stand/userboot/userboot/main.c index 1f0901dc699..7237b0e841c 100644 --- a/stand/userboot/userboot/main.c +++ b/stand/userboot/userboot/main.c @@ -159,7 +159,6 @@ extract_currdev(void) //bzero(&dev, sizeof(dev)); #if defined(USERBOOT_ZFS_SUPPORT) - CTASSERT(sizeof(struct disk_devdesc) >= sizeof(struct zfs_devdesc)); if (userboot_zfs_found) { struct zfs_devdesc zdev; diff --git a/stand/zfs/libzfs.h b/stand/zfs/libzfs.h index 4b1e636b2e6..76b05009c80 100644 --- a/stand/zfs/libzfs.h +++ b/stand/zfs/libzfs.h @@ -33,12 +33,9 @@ /* * ZFS fully-qualified device descriptor. - * Arch-specific device descriptors should be binary compatible with this - * structure if they are to support ZFS. */ -/* Note: Must match the 'struct devdesc' in stand.h */ struct zfs_devdesc { - struct devdesc dd; + struct devdesc dd; /* Must be first. */ uint64_t pool_guid; uint64_t root_guid; }; -- 2.45.0