---- hash_page.c.orig Thu Mar 21 14:46:26 2002
-+++ hash_page.c Sat Oct 18 18:31:10 2003
+--- hash_page.c.orig 2006-04-22 23:04:55.000000000 -0700
++++ hash_page.c 2006-04-23 00:23:46.000000000 -0700
@@ -74,7 +74,7 @@
#include <db.h>
#include "hash.h"
static u_int32_t *fetch_bitmap(HTAB *, int);
static u_int32_t first_free(u_int32_t);
+@@ -586,7 +586,7 @@
+ int is_bucket, is_bitmap;
+ {
+ int fd, page, size;
+- int wsize;
++ int wsize, max;
+
+ size = hashp->BSIZE;
+ if ((hashp->fp == -1) && open_temp(hashp))
+@@ -595,7 +595,6 @@
+
+ if (hashp->LORDER != BYTE_ORDER) {
+ int i;
+- int max;
+
+ if (is_bitmap) {
+ max = hashp->BSIZE >> 2; /* divide by 4 */
+@@ -619,6 +618,18 @@
+ errno = EFTYPE;
+ return (-1);
+ }
++ /* 4485533 - reswap the in-memory copy */
++ if (hashp->LORDER != BYTE_ORDER) {
++ int i;
++
++ if (is_bitmap) {
++ for (i = 0; i < max; i++)
++ M_32_SWAP(((int *)p)[i]);
++ } else {
++ for (i = 0; i <= max; i++)
++ M_16_SWAP(((u_int16_t *)p)[i]);
++ }
++ }
+ return (0);
+ }
+
/*-
- * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
+ * Copyright (c) 2004, 2005 David Schultz <das@FreeBSD.ORG>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/gdtoa/_hdtoa.c,v 1.2 2004/01/21 04:51:50 grehan Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/gdtoa/_hdtoa.c,v 1.3 2005/01/18 18:44:07 das Exp $");
#include <float.h>
-#include <inttypes.h>
#include <limits.h>
#include <math.h>
-#include <stdlib.h>
#include "fpmath.h"
#include "gdtoaimp.h"
#define INFSTR "Infinity"
#define NANSTR "NaN"
-#define DBL_BIAS (DBL_MAX_EXP - 1)
-#define LDBL_BIAS (LDBL_MAX_EXP - 1)
-
-#ifdef LDBL_IMPLICIT_NBIT
-#define LDBL_NBIT_ADJ 0
-#else
-#define LDBL_NBIT_ADJ 1
-#endif
-
-/*
- * Efficiently compute the log2 of an integer. Uses a combination of
- * arcane tricks found in fortune and arcane tricks not (yet) in
- * fortune. This routine behaves similarly to fls(9).
- */
-static int
-log2_32(uint32_t n)
-{
-
- n |= (n >> 1);
- n |= (n >> 2);
- n |= (n >> 4);
- n |= (n >> 8);
- n |= (n >> 16);
-
- n = (n & 0x55555555) + ((n & 0xaaaaaaaa) >> 1);
- n = (n & 0x33333333) + ((n & 0xcccccccc) >> 2);
- n = (n & 0x0f0f0f0f) + ((n & 0xf0f0f0f0) >> 4);
- n = (n & 0x00ff00ff) + ((n & 0xff00ff00) >> 8);
- n = (n & 0x0000ffff) + ((n & 0xffff0000) >> 16);
- return (n - 1);
-}
-
-#if (LDBL_MANH_SIZE > 32 || LDBL_MANL_SIZE > 32)
-
-static int
-log2_64(uint64_t n)
-{
-
- if (n >> 32 != 0)
- return (log2_32((uint32_t)(n >> 32)) + 32);
- else
- return (log2_32((uint32_t)n));
-}
-
-#endif /* (LDBL_MANH_SIZE > 32 || LDBL_MANL_SIZE > 32) */
+#define DBL_ADJ (DBL_MAX_EXP - 2 + ((DBL_MANT_DIG - 1) % 4))
+#define LDBL_ADJ (LDBL_MAX_EXP - 2 + ((LDBL_MANT_DIG - 1) % 4))
/*
* Round up the given digit string. If the digit string is fff...f,
__hdtoa(double d, const char *xdigs, int ndigits, int *decpt, int *sign,
char **rve)
{
+ static const int sigfigs = (DBL_MANT_DIG + 3) / 4;
union IEEEd2bits u;
char *s, *s0;
int bufsize;
- int impnbit; /* implicit normalization bit */
- int pos;
- int shift; /* for subnormals, # of shifts required to normalize */
- int sigfigs; /* number of significant hex figures in result */
u.d = d;
*sign = u.bits.sign;
switch (fpclassify(d)) {
case FP_NORMAL:
- sigfigs = (DBL_MANT_DIG + 3) / 4;
- impnbit = 1 << ((DBL_MANT_DIG - 1) % 4);
- *decpt = u.bits.exp - DBL_BIAS + 1 -
- ((DBL_MANT_DIG - 1) % 4);
+ *decpt = u.bits.exp - DBL_ADJ;
break;
case FP_ZERO:
*decpt = 1;
return (nrv_alloc("0", rve, 1));
case FP_SUBNORMAL:
- /*
- * The position of the highest-order bit tells us by
- * how much to adjust the exponent (decpt). The
- * adjustment is raised to the next nibble boundary
- * since we will later choose the leftmost hexadecimal
- * digit so that all subsequent digits align on nibble
- * boundaries.
- */
- if (u.bits.manh != 0) {
- pos = log2_32(u.bits.manh);
- shift = DBL_MANH_SIZE - pos;
- } else {
- pos = log2_32(u.bits.manl);
- shift = DBL_MANH_SIZE + DBL_MANL_SIZE - pos;
- }
- sigfigs = (3 + DBL_MANT_DIG - shift) / 4;
- impnbit = 0;
- *decpt = DBL_MIN_EXP - ((shift + 3) & ~(4 - 1));
+ u.d *= 0x1p514;
+ *decpt = u.bits.exp - (514 + DBL_ADJ);
break;
case FP_INFINITE:
*decpt = INT_MAX;
* At this point, we have snarfed all the bits in the
* mantissa, with the possible exception of the highest-order
* (partial) nibble, which is dealt with by the next
- * statement. That nibble is usually in manh, but it could be
- * in manl instead for small subnormals. We also tack on the
- * implicit normalization bit if appropriate.
+ * statement. We also tack on the implicit normalization bit.
*/
- *s = u.bits.manh | u.bits.manl | impnbit;
+ *s = u.bits.manh | (1U << ((DBL_MANT_DIG - 1) % 4));
/* If ndigits < 0, we are expected to auto-size the precision. */
if (ndigits < 0) {
/*
* This is the long double version of __hdtoa().
- *
- * On architectures that have an explicit integer bit, unnormals and
- * pseudo-denormals cause problems in the conversion routine, so they
- * are ``fixed'' by effectively toggling the integer bit. Although
- * this is not correct behavior, the hardware will not produce these
- * formats externally.
*/
char *
__hldtoa(long double e, const char *xdigs, int ndigits, int *decpt, int *sign,
char **rve)
{
+ static const int sigfigs = (LDBL_MANT_DIG + 3) / 4;
union IEEEl2bits u;
char *s, *s0;
int bufsize;
- int impnbit; /* implicit normalization bit */
- int pos;
- int shift; /* for subnormals, # of shifts required to normalize */
- int sigfigs; /* number of significant hex figures in result */
u.e = e;
*sign = u.bits.sign;
switch (fpclassify(e)) {
case FP_NORMAL:
- sigfigs = (LDBL_MANT_DIG + 3) / 4;
- impnbit = 1 << ((LDBL_MANT_DIG - 1) % 4);
- *decpt = u.bits.exp - LDBL_BIAS + 1 -
- ((LDBL_MANT_DIG - 1) % 4);
+ *decpt = u.bits.exp - LDBL_ADJ;
break;
case FP_ZERO:
*decpt = 1;
return (nrv_alloc("0", rve, 1));
case FP_SUBNORMAL:
- /*
- * The position of the highest-order bit tells us by
- * how much to adjust the exponent (decpt). The
- * adjustment is raised to the next nibble boundary
- * since we will later choose the leftmost hexadecimal
- * digit so that all subsequent digits align on nibble
- * boundaries.
- */
-#ifdef LDBL_IMPLICIT_NBIT
- /* Don't trust the normalization bit to be off. */
- u.bits.manh &= ~(~0ULL << (LDBL_MANH_SIZE - 1));
-#endif
- if (u.bits.manh != 0) {
-#if LDBL_MANH_SIZE > 32
- pos = log2_64(u.bits.manh);
-#else
- pos = log2_32(u.bits.manh);
-#endif
- shift = LDBL_MANH_SIZE - LDBL_NBIT_ADJ - pos;
- } else {
-#if LDBL_MANL_SIZE > 32
- pos = log2_64(u.bits.manl);
-#else
- pos = log2_32(u.bits.manl);
-#endif
- shift = LDBL_MANH_SIZE + LDBL_MANL_SIZE -
- LDBL_NBIT_ADJ - pos;
- }
- sigfigs = (3 + LDBL_MANT_DIG - LDBL_NBIT_ADJ - shift) / 4;
- *decpt = LDBL_MIN_EXP + LDBL_NBIT_ADJ -
- ((shift + 3) & ~(4 - 1));
- impnbit = 0;
+ u.e *= 0x1p514L;
+ *decpt = u.bits.exp - (514 + LDBL_ADJ);
break;
case FP_INFINITE:
*decpt = INT_MAX;
* At this point, we have snarfed all the bits in the
* mantissa, with the possible exception of the highest-order
* (partial) nibble, which is dealt with by the next
- * statement. That nibble is usually in manh, but it could be
- * in manl instead for small subnormals. We also tack on the
- * implicit normalization bit if appropriate.
+ * statement. We also tack on the implicit normalization bit.
*/
- *s = u.bits.manh | u.bits.manl | impnbit;
+ *s = u.bits.manh | (1U << ((LDBL_MANT_DIG - 1) % 4));
/* If ndigits < 0, we are expected to auto-size the precision. */
if (ndigits < 0) {
---- _hdtoa.c.orig 2004-06-03 15:22:08.000000000 -0700
-+++ _hdtoa.c 2004-08-28 17:10:21.000000000 -0700
-@@ -32,6 +32,9 @@
- #include <limits.h>
- #include <math.h>
- #include <stdlib.h>
-+#ifdef LDBL_HEAD_TAIL_PAIR
-+#include <alloca.h>
-+#endif /* LDBL_HEAD_TAIL_PAIR */
- #include "fpmath.h"
- #include "gdtoaimp.h"
-
-@@ -301,16 +304,31 @@
- int pos;
- int shift; /* for subnormals, # of shifts required to normalize */
- int sigfigs; /* number of significant hex figures in result */
+--- _hdtoa.c.orig 2006-01-31 15:21:41.000000000 -0800
++++ _hdtoa.c 2006-01-31 23:37:12.000000000 -0800
+@@ -223,6 +223,10 @@
+ union IEEEl2bits u;
+ char *s, *s0;
+ int bufsize;
+#ifdef LDBL_HEAD_TAIL_PAIR
+ uint32_t bits[4];
-+ int i;
++ int i, pos;
+#endif /* LDBL_HEAD_TAIL_PAIR */
u.e = e;
*sign = u.bits.sign;
-
-+#ifdef LDBL_HEAD_TAIL_PAIR
-+ switch (__fpclassifyd(u.d[0])) {
-+#else /* LDBL_HEAD_TAIL_PAIR */
- switch (fpclassify(e)) {
-+#endif /* LDBL_HEAD_TAIL_PAIR */
- case FP_NORMAL:
-+#ifdef LDBL_HEAD_TAIL_PAIR
- sigfigs = (LDBL_MANT_DIG + 3) / 4;
- impnbit = 1 << ((LDBL_MANT_DIG - 1) % 4);
- *decpt = u.bits.exp - LDBL_BIAS + 1 -
- ((LDBL_MANT_DIG - 1) % 4);
-+#else /* LDBL_HEAD_TAIL_PAIR */
-+ sigfigs = (LDBL_MANT_DIG + 3) / 4;
-+ impnbit = 1 << ((LDBL_MANT_DIG - 1) % 4);
-+ *decpt = u.bits.exp - LDBL_BIAS + 1 -
-+ ((LDBL_MANT_DIG - 1) % 4);
-+#endif /* LDBL_HEAD_TAIL_PAIR */
- break;
- case FP_ZERO:
- *decpt = 1;
-@@ -328,13 +346,26 @@
- /* Don't trust the normalization bit to be off. */
- u.bits.manh &= ~(~0ULL << (LDBL_MANH_SIZE - 1));
- #endif
-+#ifndef LDBL_HEAD_TAIL_PAIR
- if (u.bits.manh != 0) {
-+#endif /* LDBL_HEAD_TAIL_PAIR */
- #if LDBL_MANH_SIZE > 32
- pos = log2_64(u.bits.manh);
- #else
- pos = log2_32(u.bits.manh);
- #endif
- shift = LDBL_MANH_SIZE - LDBL_NBIT_ADJ - pos;
-+#ifdef LDBL_HEAD_TAIL_PAIR
-+ sigfigs = (3 + LDBL_MANT_DIG - LDBL_NBIT_ADJ - shift) / 4;
-+ // we use DBL_MIN_EXP below because the head double is
-+ // subnormal (and the tail double is zero)
-+ *decpt = DBL_MIN_EXP + LDBL_NBIT_ADJ;
-+ pos = (LDBL_MANT_DIG + 3) % 4;
-+ if (pos < shift)
-+ *decpt -= pos + ((shift - pos + 3) & ~(4 - 1));
-+ else
-+ *decpt -= shift;
-+#else /* LDBL_HEAD_TAIL_PAIR */
- } else {
- #if LDBL_MANL_SIZE > 32
- pos = log2_64(u.bits.manl);
-@@ -345,8 +376,9 @@
- LDBL_NBIT_ADJ - pos;
- }
- sigfigs = (3 + LDBL_MANT_DIG - LDBL_NBIT_ADJ - shift) / 4;
-- *decpt = LDBL_MIN_EXP + LDBL_NBIT_ADJ -
-+ *decpt = DBL_MIN_EXP + LDBL_NBIT_ADJ -
- ((shift + 3) & ~(4 - 1));
-+#endif /* LDBL_HEAD_TAIL_PAIR */
- impnbit = 0;
- break;
- case FP_INFINITE:
-@@ -381,6 +413,19 @@
+@@ -270,6 +274,19 @@
*/
for (s = s0 + bufsize - 1; s > s0 + sigfigs - 1; s--)
*s = 0;
for (; s > s0 + sigfigs - (LDBL_MANL_SIZE / 4) - 1 && s > s0; s--) {
*s = u.bits.manl & 0xf;
u.bits.manl >>= 4;
-@@ -389,6 +434,7 @@
+@@ -278,6 +295,7 @@
*s = u.bits.manh & 0xf;
u.bits.manh >>= 4;
}
/*
* At this point, we have snarfed all the bits in the
-@@ -398,7 +444,11 @@
- * in manl instead for small subnormals. We also tack on the
- * implicit normalization bit if appropriate.
+@@ -285,7 +303,11 @@
+ * (partial) nibble, which is dealt with by the next
+ * statement. We also tack on the implicit normalization bit.
*/
+#ifdef LDBL_HEAD_TAIL_PAIR
-+ *s = bits[i] | impnbit;
++ *s = bits[i];
+#else /* LDBL_HEAD_TAIL_PAIR */
- *s = u.bits.manh | u.bits.manl | impnbit;
+ *s = u.bits.manh | (1U << ((LDBL_MANT_DIG - 1) % 4));
+#endif /* LDBL_HEAD_TAIL_PAIR */
/* If ndigits < 0, we are expected to auto-size the precision. */
* @APPLE_LICENSE_HEADER_END@
*/
-#ifndef _OPEN_SOURCE_
-
-#define __APPLE_API_PRIVATE
-#include <machine/cpu_capabilities.h>
-#undef __APPLE_API_PRIVATE
-
-const void* __commpage_dsmos()
-{
- return ((const void*) _COMM_PAGE_SYSTEM_INTEGRITY);
-}
-
-#endif
---- msgcat.c.orig 2004-11-25 11:38:30.000000000 -0800
-+++ msgcat.c 2005-02-27 12:06:52.000000000 -0800
-@@ -45,7 +45,7 @@
+--- /Network/Servers/hills/Volumes/capanna/josborne/work-area/PR-4416984/Libc/nls/FreeBSD/msgcat.c 2004-11-25 11:38:30.000000000 -0800
++++ msgcat.c 2006-02-21 12:46:25.000000000 -0800
+@@ -45,16 +45,23 @@
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <nl_types.h>
#include <stdio.h>
#include <stdlib.h>
-@@ -54,7 +54,7 @@
+ #include <string.h>
+ #include <unistd.h>
++#include <machine/endian.h>
++#include <libkern/OSByteOrder.h>
#include "un-namespace.h"
#include "msgcat.h"
-#include "../locale/setlocale.h" /* for ENCODING_LEN */
+#include "setlocale.h" /* for ENCODING_LEN */
++
++#ifndef htonll
++#define htonll(x) OSSwapHostToBigInt64(x)
++#define ntohll(x) OSSwapBigToHostInt64(x)
++#endif
#define _DEFAULT_NLS_PATH "/usr/share/nls/%L/%N.cat:/usr/share/nls/%N/%L:/usr/local/share/nls/%L/%N.cat:/usr/local/share/nls/%N/%L"
-@@ -87,7 +87,7 @@
+@@ -87,7 +94,7 @@
return (loadCat(name));
if (type == NL_CAT_LOCALE)
else
lang = getenv("LANG");
+@@ -210,21 +217,21 @@
+
+ #define LOOKUP(PARENT, CHILD, ID, NUM, SET) { \
+ lo = 0; \
+- if (ID - 1 < PARENT->NUM) { \
++ if (ID - 1 < NUM) { \
+ cur = ID - 1; \
+ hi = ID; \
+ } else { \
+- hi = PARENT->NUM; \
++ hi = NUM; \
+ cur = (hi - lo) / 2; \
+ } \
+ while (TRUE) { \
+ CHILD = PARENT->SET + cur; \
+- if (CHILD->ID == ID) \
++ if (htonl(CHILD->ID) == ID) \
+ break; \
+- if (CHILD->ID < ID) { \
++ if (htonl(CHILD->ID) < ID) { \
+ lo = cur + 1; \
+- if (hi > cur + (ID - CHILD->ID) + 1) \
+- hi = cur + (ID - CHILD->ID) + 1; \
++ if (hi > cur + (ID - htonl(CHILD->ID)) + 1) \
++ hi = cur + (ID - htonl(CHILD->ID)) + 1; \
+ dir = 1; \
+ } else { \
+ hi = cur; \
+@@ -240,32 +247,28 @@
+ }
+
+ static MCSetT *
+-MCGetSet(cat, setId)
+- MCCatT *cat;
+- int setId;
++MCGetSet(MCCatT *cat, int setId)
+ {
+ MCSetT *set;
+ long lo, hi, cur, dir;
+
+ if (cat == NULL || setId <= 0)
+ return (NULL);
+- LOOKUP(cat, set, setId, numSets, sets);
++ LOOKUP(cat, set, setId, cat->numSets, sets);
+ if (set->invalid && loadSet(cat, set) <= 0)
+ return (NULL);
+ return (set);
+ }
+
+ static MCMsgT *
+-MCGetMsg(set, msgId)
+- MCSetT *set;
+- int msgId;
++MCGetMsg(MCSetT *set, int msgId)
+ {
+ MCMsgT *msg;
+ long lo, hi, cur, dir;
+
+ if (set == NULL || set->invalid || msgId <= 0)
+ return (NULL);
+- LOOKUP(set, msg, msgId, numMsgs, u.msgs);
++ LOOKUP(set, msg, msgId, htonl(set->numMsgs), u.msgs);
+ return (msg);
+ }
+
+@@ -377,27 +380,30 @@
+ strncmp(header.magic, MCMagic, MCMagicLen) != 0)
+ CORRUPT();
+
+- if (header.majorVer != MCMajorVer) {
++ if (htonl(header.majorVer) != MCMajorVer) {
+ (void)fclose(cat->fp);
+ free(cat);
+- (void)fprintf(stderr, "%s: %s is version %ld, we need %ld.\n",
+- _errowner, catpath, header.majorVer, MCMajorVer);
++ if (OSSwapInt32(htonl(header.majorVer)) == MCMajorVer) {
++ (void)fprintf(stderr, "%s: %s is the wrong byte ordering.\n", _errowner, catpath);
++ } else {
++ (void)fprintf(stderr, "%s: %s is version %ld, we need %ld.\n", _errowner, catpath, htonl(header.majorVer), MCMajorVer);
++ }
+ NLRETERR(EFTYPE);
+ }
+- if (header.numSets <= 0) {
++ if (htonl(header.numSets) <= 0) {
+ (void)fclose(cat->fp);
+ free(cat);
+ (void)fprintf(stderr, "%s: %s has %ld sets!\n",
+- _errowner, catpath, header.numSets);
++ _errowner, catpath, htonl(header.numSets));
+ NLRETERR(EFTYPE);
+ }
+
+- cat->numSets = header.numSets;
+- if ((cat->sets = (MCSetT *)malloc(sizeof(MCSetT) * header.numSets)) ==
++ cat->numSets = htonl(header.numSets);
++ if ((cat->sets = (MCSetT *)malloc(sizeof(MCSetT) * cat->numSets)) ==
+ NULL)
+ NOSPACE();
+
+- nextSet = header.firstSet;
++ nextSet = htonll(header.firstSet);
+ for (i = 0; i < cat->numSets; ++i) {
+ if (fseeko(cat->fp, nextSet, SEEK_SET) == -1) {
+ __nls_free_resources(cat, i);
+@@ -414,7 +420,7 @@
+ /* if it's invalid, skip over it (and backup 'i') */
+ if (set->invalid) {
+ --i;
+- nextSet = set->nextSet;
++ nextSet = htonll(set->nextSet);
+ continue;
+ }
+ #if 0
+@@ -432,7 +438,7 @@
+ } else
+ #endif
+ set->invalid = TRUE;
+- nextSet = set->nextSet;
++ nextSet = htonll(set->nextSet);
+ }
+ #if 0
+ if (cat->loadType == MCLoadAll) {
+@@ -453,11 +459,11 @@
+ int saverr;
+
+ /* Get the data */
+- if (fseeko(cat->fp, set->data.off, SEEK_SET) == -1)
++ if (fseeko(cat->fp, htonll(set->data.off), SEEK_SET) == -1)
+ return (0);
+- if ((set->data.str = malloc(set->dataLen)) == NULL)
++ if ((set->data.str = malloc(htonl(set->dataLen))) == NULL)
+ return (-1);
+- if (fread(set->data.str, set->dataLen, 1, cat->fp) != 1) {
++ if (fread(set->data.str, htonl(set->dataLen), 1, cat->fp) != 1) {
+ saverr = errno;
+ free(set->data.str);
+ errno = saverr;
+@@ -465,13 +471,13 @@
+ }
+
+ /* Get the messages */
+- if (fseeko(cat->fp, set->u.firstMsg, SEEK_SET) == -1) {
++ if (fseeko(cat->fp, htonll(set->u.firstMsg), SEEK_SET) == -1) {
+ saverr = errno;
+ free(set->data.str);
+ errno = saverr;
+ return (0);
+ }
+- if ((set->u.msgs = (MCMsgT *)malloc(sizeof(MCMsgT) * set->numMsgs)) ==
++ if ((set->u.msgs = (MCMsgT *)malloc(sizeof(MCMsgT) * htonl(set->numMsgs))) ==
+ NULL) {
+ saverr = errno;
+ free(set->data.str);
+@@ -479,7 +485,7 @@
+ return (-1);
+ }
+
+- for (i = 0; i < set->numMsgs; ++i) {
++ for (i = 0; i < htonl(set->numMsgs); ++i) {
+ msg = set->u.msgs + i;
+ if (fread(msg, sizeof(*msg), 1, cat->fp) != 1) {
+ saverr = errno;
+@@ -492,7 +498,7 @@
+ --i;
+ continue;
+ }
+- msg->msg.str = (char *)(set->data.str + msg->msg.off);
++ msg->msg.str = (char *)(set->data.str + htonll(msg->msg.off));
+ }
+ set->invalid = FALSE;
+ return (1);
---- grantpt.c.orig 2004-09-14 19:06:46.000000000 -0700
-+++ grantpt.c 2004-09-14 19:11:31.000000000 -0700
+--- grantpt.c.orig 2006-04-21 22:41:31.000000000 -0700
++++ grantpt.c 2006-04-21 22:43:03.000000000 -0700
@@ -54,18 +54,16 @@
#include <unistd.h>
#include "un-namespace.h"
minor((x).st_rdev) >= 0 && \
minor((x).st_rdev) < PT_MAX)
-@@ -227,8 +246,8 @@
+@@ -100,50 +119,53 @@
+ serrno = errno;
+
+ if ((slave = ptsname(fildes)) != NULL) {
+- /*
+- * Block SIGCHLD.
+- */
+- (void)sigemptyset(&nblock);
+- (void)sigaddset(&nblock, SIGCHLD);
+- (void)_sigprocmask(SIG_BLOCK, &nblock, &oblock);
+-
+- switch (pid = fork()) {
+- case -1:
+- break;
+- case 0: /* child */
++ /* 4430299: if we are root, we don't need to fork/exec */
++ if (geteuid() != 0) {
+ /*
+- * pt_chown expects the master pseudo TTY to be its
+- * standard input.
++ * Block SIGCHLD.
+ */
+- (void)_dup2(fildes, STDIN_FILENO);
+- (void)_sigprocmask(SIG_SETMASK, &oblock, NULL);
+- execl(_PATH_PTCHOWN, _PATH_PTCHOWN, (char *)NULL);
+- _exit(EX_UNAVAILABLE);
+- /* NOTREACHED */
+- default: /* parent */
++ (void)sigemptyset(&nblock);
++ (void)sigaddset(&nblock, SIGCHLD);
++ (void)_sigprocmask(SIG_BLOCK, &nblock, &oblock);
++
++ switch (pid = fork()) {
++ case -1:
++ break;
++ case 0: /* child */
++ /*
++ * pt_chown expects the master pseudo TTY to be its
++ * standard input.
++ */
++ (void)_dup2(fildes, STDIN_FILENO);
++ (void)_sigprocmask(SIG_SETMASK, &oblock, NULL);
++ execl(_PATH_PTCHOWN, _PATH_PTCHOWN, (char *)NULL);
++ _exit(EX_UNAVAILABLE);
++ /* NOTREACHED */
++ default: /* parent */
++ /*
++ * Just wait for the process. Error checking is
++ * done below.
++ */
++ while ((spid = _waitpid(pid, &status, 0)) == -1 &&
++ (errno == EINTR))
++ ;
++ if (spid != -1 && WIFEXITED(status) &&
++ WEXITSTATUS(status) == EX_OK)
++ retval = 0;
++ else
++ errno = EACCES;
++ break;
++ }
++
+ /*
+- * Just wait for the process. Error checking is
+- * done below.
++ * Restore process's signal mask.
+ */
+- while ((spid = _waitpid(pid, &status, 0)) == -1 &&
+- (errno == EINTR))
+- ;
+- if (spid != -1 && WIFEXITED(status) &&
+- WEXITSTATUS(status) == EX_OK)
+- retval = 0;
+- else
+- errno = EACCES;
+- break;
++ (void)_sigprocmask(SIG_SETMASK, &oblock, NULL);
+ }
+
+- /*
+- * Restore process's signal mask.
+- */
+- (void)_sigprocmask(SIG_SETMASK, &oblock, NULL);
+-
+ if (retval) {
+ /*
+- * pt_chown failed. Try to manually change the
++ * pt_chown failed (or we're root). Try to manually change the
+ * permissions for the slave.
+ */
+ gid = (grp = getgrnam("tty")) ? grp->gr_gid : -1;
+@@ -227,8 +249,8 @@
errno = EINVAL;
else {
(void)sprintf(slave, _PATH_DEV PTS_PREFIX "%c%c",