From owner-freebsd-standards Wed Nov 28 19:43: 8 2001 Delivered-To: freebsd-standards@freebsd.org Received: from khavrinen.lcs.mit.edu (khavrinen.lcs.mit.edu [18.24.4.193]) by hub.freebsd.org (Postfix) with ESMTP id E81D737B405 for ; Wed, 28 Nov 2001 19:43:04 -0800 (PST) Received: from softweyr.com (bd3d417249646c6e63098496112347fd@softweyr.com [65.88.244.127]) by khavrinen.lcs.mit.edu (8.11.4/8.11.4) with ESMTP id fAT3h3G05564 for ; Wed, 28 Nov 2001 22:43:03 -0500 (EST) (envelope-from wes@softweyr.com) Received: from homer.softweyr.com ([204.68.178.39] helo=softweyr.com) by softweyr.com with esmtp (Exim 3.33 #1) id 169IjG-0004Wh-00; Wed, 28 Nov 2001 21:23:18 -0700 Message-ID: <3C05BE3A.1DF1A539@softweyr.com> Date: Wed, 28 Nov 2001 21:48:58 -0700 From: Wes Peters Organization: Softweyr LLC X-Mailer: Mozilla 4.78 [en] (X11; U; Linux 2.2.12 i386) X-Accept-Language: en MIME-Version: 1.0 To: Bill Fenner Cc: mike@FreeBSD.org, freebsd-standards@bostonradio.org Subject: Re: strerror_r() implementation References: <20011125014216.A84711@espresso.q9media.com> <3C00A43B.9929E9C7@softweyr.com> <200111281854.KAA13574@windsor.research.att.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-standards@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Bill Fenner wrote: > > I'm still confused by why you need ERR_LEN; strerror() does: > > if (uerr < sys_nerr) > return (char *)sys_errlist[uerr]; > > so the only possible return value from strerror_r() is stored in > strerror_r()'s tmp[40] -- so strerror() can stick with ebuf[40]. No. The array tmp[] is used only to collect the ASCII version of the errno *in reverse*. The strlcpy seeds strerrbuf with the string "Unknown error: ". The loop following strlcpy un-reverses the ascii error number onto the end of the string. Ah, I see the confusion. The size of ebuf in strerror doesn't need to be big enough to hold messages from sys_errlist, it only needs to be large enough to hold "Unknown error: " plus the length of a 64-bit number in ascii. How does this look? --- strerror.c.nxt Wed Nov 28 20:32:54 2001 +++ strerror.c Wed Nov 28 20:39:30 2001 @@ -86,18 +86,17 @@ } -/* - * NOTE: the following length should be enough to hold the longest defined - * error message in sys_errlist, defined in ../gen/errlst.c. This is a WAG - * that is better than the previous value. - */ -#define ERR_LEN 64 - char * strerror(num) int num; { unsigned int uerr; + + /* + * NOTE: the following length should be enough to hold the + * longest "Unknown error: " message above. + */ +#define ERR_LEN 55 static char ebuf[ERR_LEN]; uerr = num; /* convert to unsigned */ @@ -106,7 +105,7 @@ /* strerror can't fail so handle truncation semi-elegantly */ if (strerror_r(num, ebuf, (size_t) ERR_LEN) != 0) - ebuf[ERR_LEN - 1] = '\0'; + ebuf[ERR_LEN - 1] = '\0'; return ebuf; } The last change is a whitespace error. Mustn't have any style(9) nits, right? ;^) -- "Where am I, and what am I doing in this handbasket?" Wes Peters Softweyr LLC wes@softweyr.com http://softweyr.com/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message