From patchwork Fri Nov 13 01:03:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stewart Smith X-Patchwork-Id: 544010 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 5395514142B for ; Fri, 13 Nov 2015 12:03:29 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 39ABA1A0909 for ; Fri, 13 Nov 2015 12:03:29 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from e39.co.us.ibm.com (e39.co.us.ibm.com [32.97.110.160]) (using TLSv1 with cipher CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id A59651A0734 for ; Fri, 13 Nov 2015 12:03:24 +1100 (AEDT) Received: from localhost by e39.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 12 Nov 2015 18:03:22 -0700 Received: from d01dlp02.pok.ibm.com (9.56.250.167) by e39.co.us.ibm.com (192.168.1.139) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 12 Nov 2015 18:03:21 -0700 X-IBM-Helo: d01dlp02.pok.ibm.com X-IBM-MailFrom: stewart@linux.vnet.ibm.com X-IBM-RcptTo: skiboot@lists.ozlabs.org Received: from b01cxnp23032.gho.pok.ibm.com (b01cxnp23032.gho.pok.ibm.com [9.57.198.27]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id 47B126E8047 for ; Thu, 12 Nov 2015 19:51:31 -0500 (EST) Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id tAD13K3Q62390450 for ; Fri, 13 Nov 2015 01:03:20 GMT Received: from d01av02.pok.ibm.com (localhost [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id tAD13KAF025251 for ; Thu, 12 Nov 2015 20:03:20 -0500 Received: from oc8180480414.ibm.com (oc8180480414.ibm.com.au.ibm.com [9.185.215.29]) by d01av02.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id tAD13JRs025115; Thu, 12 Nov 2015 20:03:19 -0500 Received: from ka1.ozlabs.ibm.com (localhost [127.0.0.1]) by oc8180480414.ibm.com (Postfix) with ESMTP id 0AF27563E; Fri, 13 Nov 2015 12:03:18 +1100 (AEDT) From: Stewart Smith To: skiboot@lists.ozlabs.org Date: Fri, 13 Nov 2015 12:03:16 +1100 Message-Id: <1447376596-4864-1-git-send-email-stewart@linux.vnet.ibm.com> X-Mailer: git-send-email 2.1.4 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15111301-0033-0000-0000-000006D17156 Subject: [Skiboot] [PATCH] Remove unused scanf and variants X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" We don't use scanf at all, so solve the bugs found by static analysis by just removing it. Signed-off-by: Stewart Smith --- libc/stdio/Makefile.inc | 6 +- libc/stdio/fscanf.c | 26 ----- libc/stdio/scanf.c | 26 ----- libc/stdio/vfscanf.c | 269 ------------------------------------------------ libc/stdio/vsscanf.c | 131 ----------------------- 5 files changed, 3 insertions(+), 455 deletions(-) delete mode 100644 libc/stdio/fscanf.c delete mode 100644 libc/stdio/scanf.c delete mode 100644 libc/stdio/vfscanf.c delete mode 100644 libc/stdio/vsscanf.c diff --git a/libc/stdio/Makefile.inc b/libc/stdio/Makefile.inc index 7c3cb08973fe..d2aee0f518f7 100644 --- a/libc/stdio/Makefile.inc +++ b/libc/stdio/Makefile.inc @@ -13,9 +13,9 @@ SUBDIRS += $(LIBCDIR)/stdio -STDIO_OBJS = fscanf.o vfprintf.o vsnprintf.o fprintf.o \ - setvbuf.o fputc.o puts.o fputs.o putchar.o scanf.o \ - stdchnls.o vfscanf.o vsscanf.o fileno.o snprintf.o +STDIO_OBJS = vfprintf.o vsnprintf.o fprintf.o \ + setvbuf.o fputc.o puts.o fputs.o putchar.o \ + stdchnls.o fileno.o snprintf.o STDIO = $(LIBCDIR)/stdio/built-in.o $(STDIO): $(STDIO_OBJS:%=$(LIBCDIR)/stdio/%) diff --git a/libc/stdio/fscanf.c b/libc/stdio/fscanf.c deleted file mode 100644 index 321b1630a88b..000000000000 --- a/libc/stdio/fscanf.c +++ /dev/null @@ -1,26 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2004, 2008 IBM Corporation - * All rights reserved. - * This program and the accompanying materials - * are made available under the terms of the BSD License - * which accompanies this distribution, and is available at - * http://www.opensource.org/licenses/bsd-license.php - * - * Contributors: - * IBM Corporation - initial implementation - *****************************************************************************/ - -#include - -int -fscanf(FILE *stream, const char *fmt, ...) -{ - int count; - va_list ap; - - va_start(ap, fmt); - count = vfscanf(stream, fmt, ap); - va_end(ap); - - return count; -} diff --git a/libc/stdio/scanf.c b/libc/stdio/scanf.c deleted file mode 100644 index 96b639980eeb..000000000000 --- a/libc/stdio/scanf.c +++ /dev/null @@ -1,26 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2004, 2008 IBM Corporation - * All rights reserved. - * This program and the accompanying materials - * are made available under the terms of the BSD License - * which accompanies this distribution, and is available at - * http://www.opensource.org/licenses/bsd-license.php - * - * Contributors: - * IBM Corporation - initial implementation - *****************************************************************************/ - -#include - -int -scanf(const char *fmt, ...) -{ - int count; - va_list ap; - - va_start(ap, fmt); - count = vfscanf(stdin, fmt, ap); - va_end(ap); - - return count; -} diff --git a/libc/stdio/vfscanf.c b/libc/stdio/vfscanf.c deleted file mode 100644 index 85ca8be5d8df..000000000000 --- a/libc/stdio/vfscanf.c +++ /dev/null @@ -1,269 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2004, 2008 IBM Corporation - * All rights reserved. - * This program and the accompanying materials - * are made available under the terms of the BSD License - * which accompanies this distribution, and is available at - * http://www.opensource.org/licenses/bsd-license.php - * - * Contributors: - * IBM Corporation - initial implementation - *****************************************************************************/ - -#include "string.h" -#include "ctype.h" -#include "stdlib.h" -#include "stdio.h" -#include "unistd.h" - - -static int -_getc(FILE * stream) -{ - int count; - char c; - - if (stream->mode == _IONBF || stream->buf == NULL) { - if (read(stream->fd, &c, 1) == 1) - return (int) c; - else - return EOF; - } - - if (stream->pos == 0 || stream->pos >= BUFSIZ || - stream->buf[stream->pos] == '\0') { - count = read(stream->fd, stream->buf, BUFSIZ); - if (count < 0) - count = 0; - if (count < BUFSIZ) - stream->buf[count] = '\0'; - stream->pos = 0; - } - - return stream->buf[stream->pos++]; -} - -static void -_ungetc(int ch, FILE * stream) -{ - if (stream->mode != _IONBF && stream->pos > 0) { - if (stream->pos < BUFSIZ) - stream->buf[stream->pos] = ch; - stream->pos--; - } -} - -static int -_is_voidage(int ch) -{ - if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r' || ch == '\0') - return 1; - else - return 0; -} - - -static int -_scanf(FILE * stream, const char *fmt, va_list * ap) -{ - int i = 0; - int length = 0; - - fmt++; - - while (*fmt != '\0') { - - char tbuf[256]; - char ch; - - switch (*fmt) { - case 'd': - case 'i': - ch = _getc(stream); - if (length == 0) { - while (!_is_voidage(ch) && isdigit(ch)) { - tbuf[i] = ch; - ch = _getc(stream); - i++; - } - } else { - while (!_is_voidage(ch) && i < length - && isdigit(ch)) { - tbuf[i] = ch; - ch = _getc(stream); - i++; - } - } - /* We tried to understand what this is good for... - * but we did not. We know for sure that it does not - * work on SLOF if this is active. */ - /* _ungetc(ch, stream); */ - tbuf[i] = '\0'; - - /* ch = _getc(stream); */ - if (!_is_voidage(ch)) - _ungetc(ch, stream); - - if (strlen(tbuf) == 0) - return 0; - - *(va_arg(*ap, int *)) = strtol(tbuf, NULL, 10); - break; - case 'X': - case 'x': - ch = _getc(stream); - if (length == 0) { - while (!_is_voidage(ch) && isxdigit(ch)) { - tbuf[i] = ch; - ch = _getc(stream); - i++; - } - } else { - while (!_is_voidage(ch) && i < length - && isxdigit(ch)) { - tbuf[i] = ch; - ch = _getc(stream); - i++; - } - } - /* _ungetc(ch, stream); */ - tbuf[i] = '\0'; - - /* ch = _getc(stream); */ - if (!_is_voidage(ch)) - _ungetc(ch, stream); - - if (strlen(tbuf) == 0) - return 0; - - *(va_arg(*ap, int *)) = strtol(tbuf, NULL, 16); - break; - case 'O': - case 'o': - ch = _getc(stream); - if (length == 0) { - while (!_is_voidage(ch) - && !(ch < '0' || ch > '7')) { - tbuf[i] = ch; - ch = _getc(stream); - i++; - } - } else { - while (!_is_voidage(ch) && i < length - && !(ch < '0' || ch > '7')) { - tbuf[i] = ch; - ch = _getc(stream); - i++; - } - } - /* _ungetc(ch, stream); */ - tbuf[i] = '\0'; - - /* ch = _getc(stream); */ - if (!_is_voidage(ch)) - _ungetc(ch, stream); - - if (strlen(tbuf) == 0) - return 0; - - *(va_arg(*ap, int *)) = strtol(tbuf, NULL, 8); - break; - case 'c': - ch = _getc(stream); - while (_is_voidage(ch)) - ch = _getc(stream); - - *(va_arg(*ap, char *)) = ch; - - ch = _getc(stream); - if (!_is_voidage(ch)) - _ungetc(ch, stream); - - break; - case 's': - ch = _getc(stream); - if (length == 0) { - while (!_is_voidage(ch)) { - tbuf[i] = ch; - ch = _getc(stream); - i++; - } - } else { - while (!_is_voidage(ch) && i < length) { - tbuf[i] = ch; - ch = _getc(stream); - i++; - } - } - /* _ungetc(ch, stream); */ - tbuf[i] = '\0'; - - /* ch = _getc(stream); */ - if (!_is_voidage(ch)) - _ungetc(ch, stream); - - strcpy(va_arg(*ap, char *), tbuf); - break; - default: - if (*fmt >= '0' && *fmt <= '9') - length += *fmt - '0'; - break; - } - fmt++; - } - - return 1; -} - - - -int -vfscanf(FILE * stream, const char *fmt, va_list ap) -{ - int args = 0; - - while (*fmt != '\0') { - - if (*fmt == '%') { - - char formstr[20]; - int i = 0; - - do { - formstr[i] = *fmt; - fmt++; - i++; - } while (! - (*fmt == 'd' || *fmt == 'i' || *fmt == 'x' - || *fmt == 'X' || *fmt == 'p' || *fmt == 'c' - || *fmt == 's' || *fmt == '%' || *fmt == 'O' - || *fmt == 'o')); - formstr[i++] = *fmt; - formstr[i] = '\0'; - if (*fmt != '%') { - if (_scanf(stream, formstr, &ap) <= 0) - return args; - else - args++; - } - - } - - fmt++; - - } - - return args; -} - -int -getc(FILE * stream) -{ - return _getc(stream); -} - -int -getchar(void) -{ - return _getc(stdin); -} diff --git a/libc/stdio/vsscanf.c b/libc/stdio/vsscanf.c deleted file mode 100644 index b9603e98ba8e..000000000000 --- a/libc/stdio/vsscanf.c +++ /dev/null @@ -1,131 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2004, 2008 IBM Corporation - * All rights reserved. - * This program and the accompanying materials - * are made available under the terms of the BSD License - * which accompanies this distribution, and is available at - * http://www.opensource.org/licenses/bsd-license.php - * - * Contributors: - * IBM Corporation - initial implementation - *****************************************************************************/ - -#include "stdio.h" -#include "stdlib.h" -#include "string.h" - - -static void -_scanf(const char **buffer, const char *fmt, va_list *ap) -{ - int i; - int length = 0; - - fmt++; - - while(*fmt != '\0') { - - char tbuf[256]; - - switch(*fmt) { - case 'd': - case 'i': - if(length == 0) length = 256; - - for(i = 0; **buffer != ' ' && **buffer != '\t' && **buffer != '\n' && i < length; i++) { - tbuf[i] = **buffer; - *buffer += 1; - } - tbuf[i] = '\0'; - - *(va_arg(*ap, int *)) = strtol(tbuf, NULL, 10); - break; - case 'X': - case 'x': - if(length == 0) length = 256; - - for(i = 0; **buffer != ' ' && **buffer != '\t' && **buffer != '\n' && i < length; i++) { - tbuf[i] = **buffer; - *buffer += 1; - } - tbuf[i] = '\0'; - - *(va_arg(*ap, int *)) = strtol(tbuf, NULL, 16); - break; - case 'O': - case 'o': - if(length == 0) length = 256; - - for(i = 0; **buffer != ' ' && **buffer != '\t' && **buffer != '\n' && i < length; i++) { - tbuf[i] = **buffer; - *buffer += 1; - } - tbuf[i] = '\0'; - - *(va_arg(*ap, int *)) = strtol(tbuf, NULL, 8); - break; - case 'c': - *(va_arg(*ap, char *)) = **buffer; - *buffer += 1; - if(length > 1) - for(i = 1; i < length; i++) - *buffer += 1; - break; - case 's': - if(length == 0) length = 256; - - for(i = 0; **buffer != ' ' && **buffer != '\t' && **buffer != '\n' && i < length; i++) { - tbuf[i] = **buffer; - *buffer += 1; - } - - tbuf[i] = '\0'; - - strcpy(va_arg(*ap, char *), tbuf); - break; - default: - if(*fmt >= '0' && *fmt <= '9') - length += *fmt - '0'; - break; - } - fmt++; - } - -} - - -int -vsscanf(const char *buffer, const char *fmt, va_list ap) -{ - - while(*fmt != '\0') { - - if(*fmt == '%') { - - char formstr[20]; - int i=0; - - do { - formstr[i] = *fmt; - fmt++; - i++; - } while(!(*fmt == 'd' || *fmt == 'i' || *fmt == 'x' || *fmt == 'X' - || *fmt == 'p' || *fmt == 'c' || *fmt == 's' || *fmt == '%' - || *fmt == 'O' || *fmt == 'o' )); - formstr[i++] = *fmt; - formstr[i] = '\0'; - if(*fmt != '%') { - while(*buffer == ' ' || *buffer == '\t' || *buffer == '\n') - buffer++; - _scanf(&buffer, formstr, &ap); - } - - } - - fmt++; - - } - - return 0; -} -