CVS commit: src/lib/libc/compat/gen

2020-05-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu May 21 05:56:31 UTC 2020

Modified Files:
src/lib/libc/compat/gen: compat_ldexp_ieee754.c

Log Message:
Teach libc's compat ldexp stub to raise fp exceptions.

This ldexp stub will shadow the ldexp weak alias for scalbn in libm,
which is unfortunate but hard to fix properly without chasing the
mythical libc bump beast.  With the change here, we should raise all
the same exceptions that libm's scalbn does -- overflow, underflow,
inexact-result, and (for signalling NaN only) invalid-operation.
This in turn should correct the missing overflow/underflow exceptions
of our portable C fma, and perhaps other routines.

XXX pullup


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/libc/compat/gen/compat_ldexp_ieee754.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/compat/gen/compat_ldexp_ieee754.c
diff -u src/lib/libc/compat/gen/compat_ldexp_ieee754.c:1.7 src/lib/libc/compat/gen/compat_ldexp_ieee754.c:1.8
--- src/lib/libc/compat/gen/compat_ldexp_ieee754.c:1.7	Sat Aug 27 09:35:13 2016
+++ src/lib/libc/compat/gen/compat_ldexp_ieee754.c	Thu May 21 05:56:31 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_ldexp_ieee754.c,v 1.7 2016/08/27 09:35:13 christos Exp $ */
+/* $NetBSD: compat_ldexp_ieee754.c,v 1.8 2020/05/21 05:56:31 riastradh Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -31,14 +31,34 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: compat_ldexp_ieee754.c,v 1.7 2016/08/27 09:35:13 christos Exp $");
+__RCSID("$NetBSD: compat_ldexp_ieee754.c,v 1.8 2020/05/21 05:56:31 riastradh Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include 
+
 #include 
+
 #include 
+#include 
+#include 
+
+static volatile const double tiny = DBL_MIN, huge = DBL_MAX;
+
+static double
+underflow(double val)
+{
+
+	errno = ERANGE;
+	return (val < 0 ? -tiny*tiny : tiny*tiny);
+}
+
+static double
+overflow(double val)
+{
 
-double ldexp(double, int);
+	errno = ERANGE;
+	return (val < 0 ? -huge*huge : huge*huge);
+}
 
 /*
  * Multiply the given value by 2^expon.
@@ -53,10 +73,13 @@ ldexp(double val, int expon)
 	oldexp = u.dblu_dbl.dbl_exp;
 
 	/*
-	 * If input is zero, Inf or NaN, just return it.
+	 * If input is zero, Inf or NaN, just return it, but raise
+	 * invalid exception if it is a signalling NaN: adding any of
+	 * these inputs to itself gives itself as output; arithmetic on
+	 * a signalling NaN additionally raises invalid-operation.
 	 */
 	if (u.dblu_d == 0.0 || oldexp == DBL_EXP_INFNAN)
-		return (val);
+		return (val + val);
 
 	if (oldexp == 0) {
 		/*
@@ -68,17 +91,13 @@ ldexp(double val, int expon)
 			 * Optimization: if the scaling can be done in a single
 			 * multiply, or underflows, just do it now.
 			 */
-			if (expon <= -DBL_FRACBITS) {
-errno = ERANGE;
-return (val < 0.0 ? -0.0 : 0.0);
-			}
+			if (expon <= -DBL_FRACBITS)
+return underflow(val);
 			mul.dblu_d = 0.0;
 			mul.dblu_dbl.dbl_exp = expon + DBL_EXP_BIAS;
 			u.dblu_d *= mul.dblu_d;
-			if (u.dblu_d == 0.0) {
-errno = ERANGE;
-return (val < 0.0 ? -0.0 : 0.0);
-			}
+			if (u.dblu_d == 0.0)
+return underflow(val);
 			return (u.dblu_d);
 		} else {
 			/*
@@ -105,20 +124,14 @@ ldexp(double val, int expon)
 		/*
 		 * The result overflowed; return +/-Inf.
 		 */
-		u.dblu_dbl.dbl_exp = DBL_EXP_INFNAN;
-		u.dblu_dbl.dbl_frach = 0;
-		u.dblu_dbl.dbl_fracl = 0;
-		errno = ERANGE;
-		return (u.dblu_d);
+		return overflow(val);
 	} else if (newexp <= 0) {
 		/*
 		 * The output number is either denormal or underflows (see
 		 * comments in machine/ieee.h).
 		 */
-		if (newexp <= -DBL_FRACBITS) {
-			errno = ERANGE;
-			return (val < 0.0 ? -0.0 : 0.0);
-		}
+		if (newexp <= -DBL_FRACBITS)
+			return underflow(val);
 		/*
 		 * Denormalize the result.  We do this with a multiply.  If
 		 * expon is very large, it won't fit in a double, so we have



CVS commit: src/lib/libc/compat/gen

2016-08-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Aug 27 09:35:13 UTC 2016

Modified Files:
src/lib/libc/compat/gen: compat_ldexp_ieee754.c

Log Message:
remove debugging


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/compat/gen/compat_ldexp_ieee754.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/compat/gen/compat_ldexp_ieee754.c
diff -u src/lib/libc/compat/gen/compat_ldexp_ieee754.c:1.6 src/lib/libc/compat/gen/compat_ldexp_ieee754.c:1.7
--- src/lib/libc/compat/gen/compat_ldexp_ieee754.c:1.6	Sat Aug 27 05:11:56 2016
+++ src/lib/libc/compat/gen/compat_ldexp_ieee754.c	Sat Aug 27 05:35:13 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_ldexp_ieee754.c,v 1.6 2016/08/27 09:11:56 christos Exp $ */
+/* $NetBSD: compat_ldexp_ieee754.c,v 1.7 2016/08/27 09:35:13 christos Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: compat_ldexp_ieee754.c,v 1.6 2016/08/27 09:11:56 christos Exp $");
+__RCSID("$NetBSD: compat_ldexp_ieee754.c,v 1.7 2016/08/27 09:35:13 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include 
@@ -40,7 +40,6 @@ __RCSID("$NetBSD: compat_ldexp_ieee754.c
 
 double ldexp(double, int);
 
-#include 
 /*
  * Multiply the given value by 2^expon.
  */
@@ -100,7 +99,6 @@ ldexp(double val, int expon)
 	 * Calculate the new exponent and check for underflow and overflow.
 	 */
 	newexp = oldexp + expon;
-	printf("ee %#x oldexp %#x\n", oldexp, expon);
 
 	if (newexp >= DBL_EXP_INFNAN ||
 	(oldexp >= 0 && expon >= DBL_EXP_INFNAN)) {



CVS commit: src/lib/libc/compat/gen

2016-08-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Aug 27 09:11:56 UTC 2016

Modified Files:
src/lib/libc/compat/gen: compat_ldexp_ieee754.c

Log Message:
detect overflow in oldexp + newexp


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/compat/gen/compat_ldexp_ieee754.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/compat/gen/compat_ldexp_ieee754.c
diff -u src/lib/libc/compat/gen/compat_ldexp_ieee754.c:1.5 src/lib/libc/compat/gen/compat_ldexp_ieee754.c:1.6
--- src/lib/libc/compat/gen/compat_ldexp_ieee754.c:1.5	Fri Apr 23 15:04:54 2010
+++ src/lib/libc/compat/gen/compat_ldexp_ieee754.c	Sat Aug 27 05:11:56 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_ldexp_ieee754.c,v 1.5 2010/04/23 19:04:54 drochner Exp $ */
+/* $NetBSD: compat_ldexp_ieee754.c,v 1.6 2016/08/27 09:11:56 christos Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: compat_ldexp_ieee754.c,v 1.5 2010/04/23 19:04:54 drochner Exp $");
+__RCSID("$NetBSD: compat_ldexp_ieee754.c,v 1.6 2016/08/27 09:11:56 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include 
@@ -40,6 +40,7 @@ __RCSID("$NetBSD: compat_ldexp_ieee754.c
 
 double ldexp(double, int);
 
+#include 
 /*
  * Multiply the given value by 2^expon.
  */
@@ -99,8 +100,19 @@ ldexp(double val, int expon)
 	 * Calculate the new exponent and check for underflow and overflow.
 	 */
 	newexp = oldexp + expon;
+	printf("ee %#x oldexp %#x\n", oldexp, expon);
 
-	if (newexp <= 0) {
+	if (newexp >= DBL_EXP_INFNAN ||
+	(oldexp >= 0 && expon >= DBL_EXP_INFNAN)) {
+		/*
+		 * The result overflowed; return +/-Inf.
+		 */
+		u.dblu_dbl.dbl_exp = DBL_EXP_INFNAN;
+		u.dblu_dbl.dbl_frach = 0;
+		u.dblu_dbl.dbl_fracl = 0;
+		errno = ERANGE;
+		return (u.dblu_d);
+	} else if (newexp <= 0) {
 		/*
 		 * The output number is either denormal or underflows (see
 		 * comments in machine/ieee.h).
@@ -123,15 +135,6 @@ ldexp(double val, int expon)
 		mul.dblu_dbl.dbl_exp = expon + DBL_EXP_BIAS;
 		u.dblu_d *= mul.dblu_d;
 		return (u.dblu_d);
-	} else if (newexp >= DBL_EXP_INFNAN) {
-		/*
-		 * The result overflowed; return +/-Inf.
-		 */
-		u.dblu_dbl.dbl_exp = DBL_EXP_INFNAN;
-		u.dblu_dbl.dbl_frach = 0;
-		u.dblu_dbl.dbl_fracl = 0;
-		errno = ERANGE;
-		return (u.dblu_d);
 	} else {
 		/*
 		 * The result is normal; just replace the old exponent with the



CVS commit: src/lib/libc/compat/gen

2012-10-24 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Oct 24 22:10:53 UTC 2012

Modified Files:
src/lib/libc/compat/gen: Makefile.inc
Added Files:
src/lib/libc/compat/gen: compat_alloca.c

Log Message:
Add a warning when we are using the libc version of alloca(3).


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libc/compat/gen/Makefile.inc
cvs rdiff -u -r0 -r1.1 src/lib/libc/compat/gen/compat_alloca.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/compat/gen/Makefile.inc
diff -u src/lib/libc/compat/gen/Makefile.inc:1.15 src/lib/libc/compat/gen/Makefile.inc:1.16
--- src/lib/libc/compat/gen/Makefile.inc:1.15	Wed Oct 10 18:52:26 2012
+++ src/lib/libc/compat/gen/Makefile.inc	Wed Oct 24 18:10:52 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.15 2012/10/10 22:52:26 christos Exp $
+#	$NetBSD: Makefile.inc,v 1.16 2012/10/24 22:10:52 christos Exp $
 
 .PATH: ${COMPATDIR}/gen
 SRCS+=compat_errlist.c compat_fts.c compat___fts13.c compat___fts30.c \
@@ -9,4 +9,4 @@ SRCS+=compat_errlist.c compat_fts.c comp
 compat__sys_errlist.c compat__sys_nerr.c compat__sys_siglist.c \
 compat_time.c compat_utime.c compat_devname.c compat_alphasort.c \
 compat_getpwent.c compat___fts32.c compat_utmp.c compat___fts50.c \
-compat___unvis13.c compat_syslog.c
+compat___unvis13.c compat_syslog.c compat_alloca.c

Added files:

Index: src/lib/libc/compat/gen/compat_alloca.c
diff -u /dev/null src/lib/libc/compat/gen/compat_alloca.c:1.1
--- /dev/null	Wed Oct 24 18:10:53 2012
+++ src/lib/libc/compat/gen/compat_alloca.c	Wed Oct 24 18:10:52 2012
@@ -0,0 +1,6 @@
+#include sys/cdefs.h
+
+__warn_references(alloca,
+Warning: reference to the libc supplied alloca(3); this most likely will 
+not work. Please use the compiler provided version of alloca(3), by 
+supplying the appropriate compiler flags (e.g. not -std=c89).)



CVS commit: src/lib/libc/compat/gen

2012-10-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Oct 10 22:52:26 UTC 2012

Modified Files:
src/lib/libc/compat/gen: Makefile.inc
Added Files:
src/lib/libc/compat/gen: compat_syslog.c

Log Message:
Add compat functions for syslog.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/libc/compat/gen/Makefile.inc
cvs rdiff -u -r0 -r1.1 src/lib/libc/compat/gen/compat_syslog.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/compat/gen/Makefile.inc
diff -u src/lib/libc/compat/gen/Makefile.inc:1.14 src/lib/libc/compat/gen/Makefile.inc:1.15
--- src/lib/libc/compat/gen/Makefile.inc:1.14	Sat Mar 12 14:52:47 2011
+++ src/lib/libc/compat/gen/Makefile.inc	Wed Oct 10 18:52:26 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.14 2011/03/12 19:52:47 christos Exp $
+#	$NetBSD: Makefile.inc,v 1.15 2012/10/10 22:52:26 christos Exp $
 
 .PATH: ${COMPATDIR}/gen
 SRCS+=compat_errlist.c compat_fts.c compat___fts13.c compat___fts30.c \
@@ -9,4 +9,4 @@ SRCS+=compat_errlist.c compat_fts.c comp
 compat__sys_errlist.c compat__sys_nerr.c compat__sys_siglist.c \
 compat_time.c compat_utime.c compat_devname.c compat_alphasort.c \
 compat_getpwent.c compat___fts32.c compat_utmp.c compat___fts50.c \
-compat___unvis13.c
+compat___unvis13.c compat_syslog.c

Added files:

Index: src/lib/libc/compat/gen/compat_syslog.c
diff -u /dev/null src/lib/libc/compat/gen/compat_syslog.c:1.1
--- /dev/null	Wed Oct 10 18:52:26 2012
+++ src/lib/libc/compat/gen/compat_syslog.c	Wed Oct 10 18:52:26 2012
@@ -0,0 +1,151 @@
+/*	$NetBSD: compat_syslog.c,v 1.1 2012/10/10 22:52:26 christos Exp $	*/
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT 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.
+ */
+
+#include namespace.h
+#include sys/cdefs.h
+
+#define	__LIBC12_SOURCE__
+#include stdarg.h
+
+#include sys/types.h
+#include sys/syslog.h
+#include compat/sys/syslog.h
+
+#ifdef __weak_alias
+__weak_alias(closelog_r,_closelog_r)
+__weak_alias(openlog_r,_openlog_r)
+__weak_alias(setlogmask_r,_setlogmask_r)
+__weak_alias(syslog_r,_syslog_r)
+__weak_alias(vsyslog_r,_vsyslog_r)
+__weak_alias(syslogp_r,_syslogp_r)
+__weak_alias(vsyslogp_r,_vsyslogp_r)
+#endif /* __weak_alias */
+
+__warn_references(closelog_r,
+warning: reference to compatibility closelog_r();
+ include sys/syslog.h for correct reference)
+__warn_references(openlog_r,
+warning: reference to compatibility openlog_r();
+ include sys/syslog.h for correct reference)
+__warn_references(setlogmask_r,
+warning: reference to compatibility setlogmask_r();
+ include sys/syslog.h for correct reference)
+__warn_references(syslog_r,
+warning: reference to compatibility syslog_r();
+ include sys/syslog.h for correct reference)
+__warn_references(vsyslog_r,
+warning: reference to compatibility vsyslog_r();
+ include sys/syslog.h for correct reference)
+__warn_references(syslogp_r,
+warning: reference to compatibility syslogp_r();
+ include sys/syslog.h for correct reference)
+__warn_references(vsyslogp_r,
+warning: reference to compatibility vsyslogp_r();
+ include sys/syslog.h for correct reference)
+
+static void
+syslog_data_convert(struct syslog_data *d, const struct syslog_data60 *s)
+{
+	d-log_file = s-log_file;
+	d-log_connected = s-connected;
+	d-log_opened = s-opened;
+	d-log_stat = s-log_stat;
+	d-log_tag = s-log_tag;
+	d-log_fac = s-log_fac;
+	d-log_mask = s-log_mask;
+}
+
+void

CVS commit: src/lib/libc/compat/gen

2012-03-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Mar 15 16:47:38 UTC 2012

Modified Files:
src/lib/libc/compat/gen: compat_fts.c

Log Message:
missed one (thanks joerg)


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/compat/gen/compat_fts.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/compat/gen/compat_fts.c
diff -u src/lib/libc/compat/gen/compat_fts.c:1.5 src/lib/libc/compat/gen/compat_fts.c:1.6
--- src/lib/libc/compat/gen/compat_fts.c:1.5	Tue Mar 13 18:37:51 2012
+++ src/lib/libc/compat/gen/compat_fts.c	Thu Mar 15 12:47:38 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat_fts.c,v 1.5 2012/03/13 22:37:51 joerg Exp $	*/
+/*	$NetBSD: compat_fts.c,v 1.6 2012/03/15 16:47:38 christos Exp $	*/
 
 /*
  * Written by Jason R. Thorpe thor...@netbsd.org, October 21, 1997.
@@ -22,12 +22,14 @@
 #define	__fts_dev_t	uint32_t
 #define	__fts_level_t	short
 
-#undef fts_namelen_truncate
-#define fts_namelen_truncate(a)	\
+#ifndef ftsent_namelen
+#define ftsent_namelen_truncate(a)	\
 ((a)  USHRT_MAX ? USHRT_MAX : (unsigned short)(a))
-#undef fts_pathlen_truncate
+#endif
+#ifndef fts_pathlen_truncate
 #define ftsent_pathlen_truncate(a)	\
 ((a)  USHRT_MAX ? USHRT_MAX : (unsigned short)(a))
+#endif
 
 #include fts.h
 #include compat/include/fts.h



CVS commit: src/lib/libc/compat/gen

2012-02-08 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Wed Feb  8 12:10:17 UTC 2012

Modified Files:
src/lib/libc/compat/gen: compat_readdir.c

Log Message:
Add missing cast, fixes i386 build.  releng ok.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/compat/gen/compat_readdir.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/compat/gen/compat_readdir.c
diff -u src/lib/libc/compat/gen/compat_readdir.c:1.2 src/lib/libc/compat/gen/compat_readdir.c:1.3
--- src/lib/libc/compat/gen/compat_readdir.c:1.2	Wed Feb  8 03:24:30 2012
+++ src/lib/libc/compat/gen/compat_readdir.c	Wed Feb  8 12:10:17 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat_readdir.c,v 1.2 2012/02/08 03:24:30 christos Exp $	*/
+/*	$NetBSD: compat_readdir.c,v 1.3 2012/02/08 12:10:17 mbalmer Exp $	*/
 
 #define __LIBC12_SOURCE__
 #include namespace.h
@@ -35,7 +35,7 @@ direnttodirent12(struct dirent12 *d12, c
 	d12-d_reclen = (uint16_t)d-d_reclen;
 	d12-d_namlen = (uint8_t)MIN(d-d_namlen, sizeof(d-d_name) - 1);
 	d12-d_type = (uint8_t)d-d_type;
-	memcpy(d12-d_name, d-d_name, d12-d_namlen);
+	memcpy(d12-d_name, d-d_name, (size_t)d12-d_namlen);
 	d12-d_name[d12-d_namlen] = '\0';
 	return d12;
 }



CVS commit: src/lib/libc/compat/gen

2012-02-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Feb  8 03:24:30 UTC 2012

Modified Files:
src/lib/libc/compat/gen: compat_readdir.c

Log Message:
Restore binary compatibility with netbsd-1.x for readdir(3). Tested with
a shark tcsh dynamic binary:

tcsh: ELF 32-bit LSB executable, ARM, version 1, dynamically linked \
(uses shared libs), for NetBSD, not stripped
-rwxr-xr-x  1 root  wheel  994170 Jun 24  2004 /bin/tcsh

This would infinite loop on ls-F /dev


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/compat/gen/compat_readdir.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/compat/gen/compat_readdir.c
diff -u src/lib/libc/compat/gen/compat_readdir.c:1.1 src/lib/libc/compat/gen/compat_readdir.c:1.2
--- src/lib/libc/compat/gen/compat_readdir.c:1.1	Mon Sep 12 21:44:09 2005
+++ src/lib/libc/compat/gen/compat_readdir.c	Tue Feb  7 22:24:30 2012
@@ -1,8 +1,12 @@
-/*	$NetBSD: compat_readdir.c,v 1.1 2005/09/13 01:44:09 christos Exp $	*/
+/*	$NetBSD: compat_readdir.c,v 1.2 2012/02/08 03:24:30 christos Exp $	*/
 
 #define __LIBC12_SOURCE__
 #include namespace.h
+#include sys/param.h
 #include dirent.h
+#include errno.h
+#include string.h
+#include limits.h
 #include compat/include/dirent.h
 
 #ifdef __weak_alias
@@ -17,6 +21,42 @@ __warn_references(readdir_r,
 warning: reference to compatibility readdir_r(); include dirent.h for correct reference)
 #endif
 
-#define dirent dirent12
+static struct dirent12 *
+direnttodirent12(struct dirent12 *d12, const struct dirent *d)
+{
+	if (d == NULL)
+		return NULL;
 
-#include gen/readdir.c
+	if (d-d_fileno  UINT_MAX || d-d_namlen = sizeof(d12-d_name)) {
+		errno = ERANGE;
+		return NULL;
+	}
+	d12-d_fileno = (uint32_t)d-d_fileno;
+	d12-d_reclen = (uint16_t)d-d_reclen;
+	d12-d_namlen = (uint8_t)MIN(d-d_namlen, sizeof(d-d_name) - 1);
+	d12-d_type = (uint8_t)d-d_type;
+	memcpy(d12-d_name, d-d_name, d12-d_namlen);
+	d12-d_name[d12-d_namlen] = '\0';
+	return d12;
+}
+
+struct dirent12 *
+readdir(DIR *dirp)
+{
+	static struct dirent12 d12;
+	return direnttodirent12(d12, __readdir30(dirp));
+}
+
+int
+readdir_r(DIR *dirp, struct dirent12 *entry, struct dirent12 **result)
+{
+	int error;
+	struct dirent e, *ep;
+
+	if ((error = __readdir_r30(dirp, e, ep)) != 0)
+		return error;
+
+	*result = entry;
+	(void)direnttodirent12(entry, e);
+	return 0;
+}



CVS commit: src/lib/libc/compat/gen

2011-06-30 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri Jul  1 01:08:59 UTC 2011

Modified Files:
src/lib/libc/compat/gen: compat_utmpx.c

Log Message:
Fix memcpy usage.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/compat/gen/compat_utmpx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/compat/gen/compat_utmpx.c
diff -u src/lib/libc/compat/gen/compat_utmpx.c:1.3 src/lib/libc/compat/gen/compat_utmpx.c:1.4
--- src/lib/libc/compat/gen/compat_utmpx.c:1.3	Sun Jan 11 02:46:25 2009
+++ src/lib/libc/compat/gen/compat_utmpx.c	Fri Jul  1 01:08:59 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat_utmpx.c,v 1.3 2009/01/11 02:46:25 christos Exp $	 */
+/*	$NetBSD: compat_utmpx.c,v 1.4 2011/07/01 01:08:59 joerg Exp $	 */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 #include sys/cdefs.h
 
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: compat_utmpx.c,v 1.3 2009/01/11 02:46:25 christos Exp $);
+__RCSID($NetBSD: compat_utmpx.c,v 1.4 2011/07/01 01:08:59 joerg Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include namespace.h
@@ -79,7 +79,7 @@
 {
 	(void)memcpy(ll-ll_line, ll50-ll_line, sizeof(ll-ll_line));
 	(void)memcpy(ll-ll_host, ll50-ll_host, sizeof(ll-ll_host));
-	(void)memcpy(ll-ll_ss, ll50-ll_ss, sizeof(ll-ll_ss));
+	(void)memcpy(ll-ll_ss, ll50-ll_ss, sizeof(ll-ll_ss));
 	timeval50_to_timeval(ll50-ll_tv, ll-ll_tv);
 }
 
@@ -88,7 +88,7 @@
 {
 	(void)memcpy(ll50-ll_line, ll-ll_line, sizeof(ll50-ll_line));
 	(void)memcpy(ll50-ll_host, ll-ll_host, sizeof(ll50-ll_host));
-	(void)memcpy(ll50-ll_ss, ll-ll_ss, sizeof(ll50-ll_ss));
+	(void)memcpy(ll50-ll_ss, ll-ll_ss, sizeof(ll50-ll_ss));
 	timeval_to_timeval50(ll-ll_tv, ll50-ll_tv);
 }
 



CVS commit: src/lib/libc/compat/gen

2010-04-23 Thread Matthias Drochner
Module Name:src
Committed By:   drochner
Date:   Fri Apr 23 19:04:54 UTC 2010

Modified Files:
src/lib/libc/compat/gen: Makefile.inc compat_frexp_ieee754.c
compat_ldexp_ieee754.c compat_modf_ieee754.c

Log Message:
use the local versions of ldexp/frexp/modf again rather than pulling
in libm source code. The libm functions depend on other libm functions,
this requires symbol renaming, and with the reachover method this
is going to be a mess. Also, bundling the dependencies into one .o
file has the potential to cause symbol conflicts on static linking.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/compat/gen/Makefile.inc
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/compat/gen/compat_frexp_ieee754.c \
src/lib/libc/compat/gen/compat_ldexp_ieee754.c
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/compat/gen/compat_modf_ieee754.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/compat/gen/Makefile.inc
diff -u src/lib/libc/compat/gen/Makefile.inc:1.12 src/lib/libc/compat/gen/Makefile.inc:1.13
--- src/lib/libc/compat/gen/Makefile.inc:1.12	Sun Aug 16 19:33:39 2009
+++ src/lib/libc/compat/gen/Makefile.inc	Fri Apr 23 19:04:54 2010
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.12 2009/08/16 19:33:39 christos Exp $
+#	$NetBSD: Makefile.inc,v 1.13 2010/04/23 19:04:54 drochner Exp $
 
 .PATH: ${COMPATDIR}/gen
 SRCS+=compat_errlist.c compat_fts.c compat___fts13.c compat___fts30.c \
@@ -9,9 +9,3 @@
 compat__sys_errlist.c compat__sys_nerr.c compat__sys_siglist.c \
 compat_time.c compat_utime.c compat_devname.c compat_alphasort.c \
 compat_getpwent.c compat___fts32.c compat_utmp.c compat___fts50.c
-
-LIBMINC=-I${LIBCDIR}/../libm/src -DUSE_LIBM
-CPPFLAGS.compat_frexp_ieee754.c += ${LIBMINC}
-CPPFLAGS.compat_ldexp_ieee754.c += ${LIBMINC}
-CPPFLAGS.compat_modf_ieee754.c += ${LIBMINC}
-

Index: src/lib/libc/compat/gen/compat_frexp_ieee754.c
diff -u src/lib/libc/compat/gen/compat_frexp_ieee754.c:1.4 src/lib/libc/compat/gen/compat_frexp_ieee754.c:1.5
--- src/lib/libc/compat/gen/compat_frexp_ieee754.c:1.4	Sun Sep 28 15:19:09 2008
+++ src/lib/libc/compat/gen/compat_frexp_ieee754.c	Fri Apr 23 19:04:54 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_frexp_ieee754.c,v 1.4 2008/09/28 15:19:09 christos Exp $ */
+/* $NetBSD: compat_frexp_ieee754.c,v 1.5 2010/04/23 19:04:54 drochner Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -35,21 +35,19 @@
  * from: Header: frexp.c,v 1.1 91/07/07 04:45:01 torek Exp
  */
 
-#ifdef USE_LIBM
-#include s_frexp.c
-#else
 #include sys/cdefs.h
 #if defined(LIBC_SCCS)  !defined(lint)
 #if 0
 static char sccsid[] = @(#)frexp.c	8.1 (Berkeley) 6/4/93;
 #else
-__RCSID($NetBSD: compat_frexp_ieee754.c,v 1.4 2008/09/28 15:19:09 christos Exp $);
+__RCSID($NetBSD: compat_frexp_ieee754.c,v 1.5 2010/04/23 19:04:54 drochner Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
 #include sys/types.h
 #include machine/ieee.h
-#include math.h
+
+double frexp(double, int *);
 
 /*
  * Split the given value into a fraction in the range [0.5, 1.0) and
@@ -83,4 +81,3 @@
 		return (value);
 	}
 }
-#endif
Index: src/lib/libc/compat/gen/compat_ldexp_ieee754.c
diff -u src/lib/libc/compat/gen/compat_ldexp_ieee754.c:1.4 src/lib/libc/compat/gen/compat_ldexp_ieee754.c:1.5
--- src/lib/libc/compat/gen/compat_ldexp_ieee754.c:1.4	Sun Sep 28 18:54:30 2008
+++ src/lib/libc/compat/gen/compat_ldexp_ieee754.c	Fri Apr 23 19:04:54 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_ldexp_ieee754.c,v 1.4 2008/09/28 18:54:30 christos Exp $ */
+/* $NetBSD: compat_ldexp_ieee754.c,v 1.5 2010/04/23 19:04:54 drochner Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -29,20 +29,16 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifdef USE_LIBM
-#include s_finite.c
-#include s_scalbn.c
-#include s_ldexp.c
-#else
 #include sys/cdefs.h
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: compat_ldexp_ieee754.c,v 1.4 2008/09/28 18:54:30 christos Exp $);
+__RCSID($NetBSD: compat_ldexp_ieee754.c,v 1.5 2010/04/23 19:04:54 drochner Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include sys/types.h
 #include machine/ieee.h
 #include errno.h
-#include math.h
+
+double ldexp(double, int);
 
 /*
  * Multiply the given value by 2^expon.
@@ -145,4 +141,3 @@
 		return (u.dblu_d);
 	}
 }
-#endif

Index: src/lib/libc/compat/gen/compat_modf_ieee754.c
diff -u src/lib/libc/compat/gen/compat_modf_ieee754.c:1.3 src/lib/libc/compat/gen/compat_modf_ieee754.c:1.4
--- src/lib/libc/compat/gen/compat_modf_ieee754.c:1.3	Wed Jan 27 14:10:41 2010
+++ src/lib/libc/compat/gen/compat_modf_ieee754.c	Fri Apr 23 19:04:54 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_modf_ieee754.c,v 1.3 2010/01/27 14:10:41 drochner Exp $ */
+/* $NetBSD: compat_modf_ieee754.c,v 1.4 2010/04/23 19:04:54 drochner Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Carnegie-Mellon University.
@@ -27,13 +27,11 @@
  * rights to redistribute these changes.
  */
 

CVS commit: src/lib/libc/compat/gen

2009-10-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Oct 19 17:52:05 UTC 2009

Modified Files:
src/lib/libc/compat/gen: compat___fts13.c compat___fts30.c
compat___fts31.c compat___fts32.c compat___fts50.c compat_fts.c

Log Message:
PR/42201: NAKAJIMA Yoshihiro: fts(3): broken compatibility
As new field types were added, we did not provide overrides for older compat
versions. This restores compatibility.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/compat/gen/compat___fts13.c
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/compat/gen/compat___fts30.c \
src/lib/libc/compat/gen/compat___fts32.c
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/compat/gen/compat___fts31.c \
src/lib/libc/compat/gen/compat___fts50.c
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/compat/gen/compat_fts.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/compat/gen/compat___fts13.c
diff -u src/lib/libc/compat/gen/compat___fts13.c:1.5 src/lib/libc/compat/gen/compat___fts13.c:1.6
--- src/lib/libc/compat/gen/compat___fts13.c:1.5	Sat Jan 10 21:46:24 2009
+++ src/lib/libc/compat/gen/compat___fts13.c	Mon Oct 19 13:52:01 2009
@@ -1,10 +1,10 @@
-/*	$NetBSD: compat___fts13.c,v 1.5 2009/01/11 02:46:24 christos Exp $	*/
+/*	$NetBSD: compat___fts13.c,v 1.6 2009/10/19 17:52:01 christos Exp $	*/
 
 #include namespace.h
 #include sys/cdefs.h
 #include dirent.h
 
-#define __LIBC12_SOURCE__
+#define	__LIBC12_SOURCE__
 
 __warn_references(__fts_children13,
 warning: reference to compatibility __fts_children13();
@@ -26,31 +26,33 @@
 #include compat/sys/time.h
 #include compat/sys/stat.h
 
-#define __fts_stat_t	struct stat13
-#define	__fts_nlink_t	nlink_t
+#define	__fts_stat_t	struct stat13
 #define	__fts_ino_t	u_int32_t
 #define	__fts_length_t	u_short
 #define	__fts_number_t	long
+#define	__fts_dev_t	uint32_t
+#define	__fts_level_t	short
 
-#define stat		__stat13
-#define lstat		__lstat13
-#define fstat		__fstat13
-
-#undef fts_children
-#define fts_children __fts_children13
-#undef fts_close
-#define fts_close __fts_close13
-#undef fts_open
-#define fts_open  __fts_open13
-#undef fts_read
-#define fts_read __fts_read13
-#undef fts_set
-#define fts_set __fts_set13
+#define	stat		__stat13
+#define	lstat		__lstat13
+#define	fstat		__fstat13
+
+#undef	fts_children
+#define	fts_children __fts_children13
+#undef	fts_close
+#define	fts_close __fts_close13
+#undef	fts_open
+#define	fts_open  __fts_open13
+#undef	fts_read
+#define	fts_read __fts_read13
+#undef	fts_set
+#define	fts_set __fts_set13
 
 #include fts.h
 #include compat/include/fts.h
 
 #define	__FTS_COMPAT_TAILINGSLASH
 #define	__FTS_COMPAT_LENGTH
+#define	__FTS_COMPAT_LEVEL
 
 #include gen/fts.c

Index: src/lib/libc/compat/gen/compat___fts30.c
diff -u src/lib/libc/compat/gen/compat___fts30.c:1.2 src/lib/libc/compat/gen/compat___fts30.c:1.3
--- src/lib/libc/compat/gen/compat___fts30.c:1.2	Thu Jul 27 11:46:30 2006
+++ src/lib/libc/compat/gen/compat___fts30.c	Mon Oct 19 13:52:04 2009
@@ -1,9 +1,11 @@
-/*	$NetBSD: compat___fts30.c,v 1.2 2006/07/27 15:46:30 christos Exp $	*/
+/*	$NetBSD: compat___fts30.c,v 1.3 2009/10/19 17:52:04 christos Exp $	*/
 
 #include namespace.h
 #include sys/cdefs.h
 #include dirent.h
 
+#define	__LIBC12_SOURCE__
+
 __warn_references(__fts_children30,
 warning: reference to compatibility __fts_children30();
  include fts.h for correct reference)
@@ -21,25 +23,34 @@
  include fts.h for correct reference)
 
 #include sys/stat.h
+#include compat/sys/time.h
+#include compat/sys/stat.h
 
+#define	__fts_stat_t	struct stat30
 #define	__fts_length_t	u_short
 #define	__fts_number_t	long
+#define	__fts_dev_t	uint32_t
+#define	__fts_level_t	short
 
-#undef fts_children
-#define fts_children __fts_children30
-#undef fts_close
-#define fts_close __fts_close30
-#undef fts_open
-#define fts_open  __fts_open30
-#undef fts_read
-#define fts_read __fts_read30
-#undef fts_set
-#define fts_set __fts_set30
+#define	stat		__stat30
+#define	lstat		__lstat30
+#define	fstat		__fstat30
+
+#undef	fts_children
+#define	fts_children __fts_children30
+#undef	fts_close
+#define	fts_close __fts_close30
+#undef	fts_open
+#define	fts_open  __fts_open30
+#undef	fts_read
+#define	fts_read __fts_read30
+#undef	fts_set
+#define	fts_set __fts_set30
 
-#define __LIBC12_SOURCE__
 #include fts.h
 #include compat/include/fts.h
 
 #define	__FTS_COMPAT_LENGTH
+#define	__FTS_COMPAT_LEVEL
 
 #include gen/fts.c
Index: src/lib/libc/compat/gen/compat___fts32.c
diff -u src/lib/libc/compat/gen/compat___fts32.c:1.2 src/lib/libc/compat/gen/compat___fts32.c:1.3
--- src/lib/libc/compat/gen/compat___fts32.c:1.2	Sat Jan 10 21:46:25 2009
+++ src/lib/libc/compat/gen/compat___fts32.c	Mon Oct 19 13:52:05 2009
@@ -1,10 +1,10 @@
-/*	$NetBSD: compat___fts32.c,v 1.2 2009/01/11 02:46:25 christos Exp $	*/
+/*	$NetBSD: compat___fts32.c,v 1.3 2009/10/19 17:52:05 christos Exp $	*/
 
 

CVS commit: src/lib/libc/compat/gen

2009-06-01 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Mon Jun  1 06:04:37 UTC 2009

Modified Files:
src/lib/libc/compat/gen: compat_getpwent.c

Log Message:
fix NULL dereferences in the compat versions of getpwent, getpwnam,
and getpwuid.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/compat/gen/compat_getpwent.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/compat/gen/compat_getpwent.c
diff -u src/lib/libc/compat/gen/compat_getpwent.c:1.2 src/lib/libc/compat/gen/compat_getpwent.c:1.3
--- src/lib/libc/compat/gen/compat_getpwent.c:1.2	Sun Jan 11 02:46:25 2009
+++ src/lib/libc/compat/gen/compat_getpwent.c	Mon Jun  1 06:04:37 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat_getpwent.c,v 1.2 2009/01/11 02:46:25 christos Exp $	*/
+/*	$NetBSD: compat_getpwent.c,v 1.3 2009/06/01 06:04:37 yamt Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 #include sys/cdefs.h
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: compat_getpwent.c,v 1.2 2009/01/11 02:46:25 christos Exp $);
+__RCSID($NetBSD: compat_getpwent.c,v 1.3 2009/06/01 06:04:37 yamt Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #define __LIBC12_SOURCE__
@@ -81,6 +81,10 @@
 cvt(struct passwd *p)
 {
 	struct passwd50 *q = (void *)p;
+
+	if (q == NULL) {
+		return NULL;
+	}
 	q-pw_change = (int32_t)p-pw_change;
 	q-pw_class = p-pw_class;
 	q-pw_gecos = p-pw_gecos;