[Midnightbsd-cvs] src [11533] trunk/usr.bin/iconv/iconv.c: sync with freebsd.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Jul 7 16:31:08 EDT 2018


Revision: 11533
          http://svnweb.midnightbsd.org/src/?rev=11533
Author:   laffer1
Date:     2018-07-07 16:31:07 -0400 (Sat, 07 Jul 2018)
Log Message:
-----------
sync with freebsd.

Modified Paths:
--------------
    trunk/usr.bin/iconv/Makefile
    trunk/usr.bin/iconv/iconv.1
    trunk/usr.bin/iconv/iconv.c

Property Changed:
----------------
    trunk/usr.bin/iconv/iconv.1

Modified: trunk/usr.bin/iconv/Makefile
===================================================================
--- trunk/usr.bin/iconv/Makefile	2018-07-07 20:30:54 UTC (rev 11532)
+++ trunk/usr.bin/iconv/Makefile	2018-07-07 20:31:07 UTC (rev 11533)
@@ -1,9 +1,11 @@
 # $MidnightBSD$
+# $FreeBSD: stable/10/usr.bin/iconv/Makefile 222772 2011-06-06 20:24:17Z ed $
 # $NetBSD: Makefile,v 1.6 2009/04/14 22:15:21 lukem Exp $
 
 .include <bsd.own.mk>
 
 PROG=	iconv
+#SRCS=	iconv.c
 MAN=	iconv.1
 
 LDADD+=	-lcrypt

Modified: trunk/usr.bin/iconv/iconv.1
===================================================================
--- trunk/usr.bin/iconv/iconv.1	2018-07-07 20:30:54 UTC (rev 11532)
+++ trunk/usr.bin/iconv/iconv.1	2018-07-07 20:31:07 UTC (rev 11533)
@@ -1,4 +1,5 @@
 .\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.bin/iconv/iconv.1 219019 2011-02-25 00:04:39Z gabor $
 .\" $NetBSD: iconv.1,v 1.3 2008/03/20 11:35:44 tnozaki Exp $
 .\"
 .\" Copyright (c)2003 Citrus Project,


Property changes on: trunk/usr.bin/iconv/iconv.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/iconv/iconv.c
===================================================================
--- trunk/usr.bin/iconv/iconv.c	2018-07-07 20:30:54 UTC (rev 11532)
+++ trunk/usr.bin/iconv/iconv.c	2018-07-07 20:31:07 UTC (rev 11533)
@@ -1,4 +1,5 @@
 /* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.bin/iconv/iconv.c 287794 2015-09-14 18:52:41Z delphij $ */
 /* $NetBSD: iconv.c,v 1.16 2009/02/20 15:28:21 yamt Exp $ */
 
 /*-
@@ -41,14 +42,11 @@
 #include <string.h>
 #include <unistd.h>
 
-static unsigned long long invalids;
+static int		do_conv(FILE *, const char *, const char *, bool, bool);
+static int		do_list(unsigned int, const char * const *, void *);
+static void		usage(void) __dead2;
 
-static void		 do_conv(FILE *, const char *, const char *, bool, bool);
-static int		 do_list(unsigned int, const char * const *, void *);
-static void		 usage(void);
-
-struct option long_options[] =
-{
+static const struct option long_options[] = {
 	{"from-code",		required_argument,	NULL, 'f'},
 	{"list",		no_argument,		NULL, 'l'},
 	{"silent",		no_argument,		NULL, 's'},
@@ -69,13 +67,13 @@
 
 #define INBUFSIZE 1024
 #define OUTBUFSIZE (INBUFSIZE * 2)
-static void
+static int
 do_conv(FILE *fp, const char *from, const char *to, bool silent,
     bool hide_invalid)
 {
 	iconv_t cd;
-	char inbuf[INBUFSIZE], outbuf[OUTBUFSIZE], *out;
-	char *in;
+	char inbuf[INBUFSIZE], outbuf[OUTBUFSIZE], *in, *out;
+	unsigned long long invalids;
 	size_t inbytes, outbytes, ret;
 
 	if ((cd = iconv_open(to, from)) == (iconv_t)-1)
@@ -85,8 +83,9 @@
 		int arg = 1;
 
 		if (iconvctl(cd, ICONV_SET_DISCARD_ILSEQ, (void *)&arg) == -1)
-			err(1, NULL);
+			err(EXIT_FAILURE, NULL);
 	}
+	invalids = 0;
 	while ((inbytes = fread(inbuf, 1, INBUFSIZE, fp)) > 0) {
 		in = inbuf;
 		while (inbytes > 0) {
@@ -136,6 +135,7 @@
 		warnx("warning: invalid characters: %llu", invalids);
 
 	iconv_close(cd);
+	return (invalids > 0);
 }
 
 static int
@@ -157,11 +157,11 @@
 main(int argc, char **argv)
 {
 	FILE *fp;
-	char *opt_f, *opt_t;
-	int ch, i;
+	const char *opt_f, *opt_t;
+	int ch, i, res;
 	bool opt_c = false, opt_s = false;
 
-	opt_f = opt_t = strdup("");
+	opt_f = opt_t = "";
 
 	setlocale(LC_ALL, "");
 	setprogname(argv[0]);
@@ -187,12 +187,12 @@
 		case 'f':
 			/* from */
 			if (optarg != NULL)
-				opt_f = strdup(optarg);
+				opt_f = optarg;
 			break;
 		case 't':
 			/* to */
 			if (optarg != NULL)
-				opt_t = strdup(optarg);
+				opt_t = optarg;
 			break;
 		default:
 			usage();
@@ -203,8 +203,9 @@
 	if ((strcmp(opt_f, "") == 0) && (strcmp(opt_t, "") == 0))
 		usage();
 	if (argc == 0)
-		do_conv(stdin, opt_f, opt_t, opt_s, opt_c);
+		res = do_conv(stdin, opt_f, opt_t, opt_s, opt_c);
 	else {
+		res = 0;
 		for (i = 0; i < argc; i++) {
 			fp = (strcmp(argv[i], "-") != 0) ?
 			    fopen(argv[i], "r") : stdin;
@@ -211,10 +212,9 @@
 			if (fp == NULL)
 				err(EXIT_FAILURE, "Cannot open `%s'",
 				    argv[i]);
-			do_conv(fp, opt_f, opt_t, opt_s,
-			    opt_c);
+			res |= do_conv(fp, opt_f, opt_t, opt_s, opt_c);
 			(void)fclose(fp);
 		}
 	}
-	return (EXIT_SUCCESS);
+	return (res == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
 }



More information about the Midnightbsd-cvs mailing list