From owner-freebsd-arch@FreeBSD.ORG Fri May 4 21:33:25 2007 Return-Path: X-Original-To: arch@freebsd.org Delivered-To: freebsd-arch@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 3606E16A401; Fri, 4 May 2007 21:33:25 +0000 (UTC) (envelope-from ache@nagual.pp.ru) Received: from nagual.pp.ru (nagual.pp.ru [194.87.13.69]) by mx1.freebsd.org (Postfix) with ESMTP id A943313C459; Fri, 4 May 2007 21:33:24 +0000 (UTC) (envelope-from ache@nagual.pp.ru) Received: from nagual.pp.ru (ache@localhost [127.0.0.1]) by nagual.pp.ru (8.14.1/8.14.1) with ESMTP id l44LXDL7034777; Sat, 5 May 2007 01:33:13 +0400 (MSD) (envelope-from ache@nagual.pp.ru) Received: (from ache@localhost) by nagual.pp.ru (8.14.1/8.14.1/Submit) id l44LXDJ0034776; Sat, 5 May 2007 01:33:13 +0400 (MSD) (envelope-from ache) Date: Sat, 5 May 2007 01:33:12 +0400 From: Andrey Chernov To: "Sean C. Farley" Message-ID: <20070504213312.GA33163@nagual.pp.ru> References: <20070501083009.GA4627@nagual.pp.ru> <20070501160645.GA9333@nagual.pp.ru> <20070501135439.B36275@thor.farley.org> <20070502.102822.-957833022.imp@bsdimp.com> <20070502183100.P1317@baba.farley.org> <20070502230413.Y30614@thor.farley.org> <20070503160351.GA15008@nagual.pp.ru> <20070504085905.J39482@thor.farley.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20070504085905.J39482@thor.farley.org> User-Agent: Mutt/1.5.15 (2007-04-06) Cc: Daniel Eischen , arch@freebsd.org Subject: Re: HEADS DOWN X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 May 2007 21:33:25 -0000 On Fri, May 04, 2007 at 01:21:50PM -0500, Sean C. Farley wrote: > I believe I check all that you did in your changes. Mine looks a little > different since some checks were combined for speed (i.e., > __strleneq()). Looking at http://www.farley.org/freebsd/tmp/setenv-8/POSIX/sysenv.c __strleneq() - "Inline strlen() for performance." - no performance gain such way but lost, because strlen() already auto-inlined with gcc -O2 in much better assembler form: repnz scasb So there is no point to call __strleneq(..., false); too instead of just strlen() (which will be auto-inlined by gcc) directly. Currently __clean_env is unused. Why don't #if 0 it? I think "Check for malformed name" should be before "Initialize environment" - with malformed arg complex environment mallocing/copying initialization ever not needed. In __build_env() when strdup() returns NULL, you better free all previous strdups in that loop and envVars too before returning (-1) Why you use strstr(envVars[envNdx].name, "="); instead of strchr(envVars[envNdx].name, '='); ? In theory strchr() can be gcc-inlined or assembler-implemented with more probability than strstr() (currently both are not inlined at i386). __rebuild_environ() needs to use realloc() instead of reallocf() because realloc() not touch original pointer/content when fails. I.e. _whole_ "environ" will not be lost in case can't be enlarged. Something like that: TempEnvironSize = newEnvSize * 2; TempEnviron = realloc(environ, sizeof (*environ) * (TempEnvironSize + 1)); if (TempEnviron == NULL) return (-1); environ = TempEnviron; environSize = TempEnvironSize; > The only other question I have is about leading whitespace in the name > passed to *env(): > 1. Should it be removed up to the first non-whitespace character? > 2. Treated as part of the variable name. Is this allowed by the > specification? > 3. Return errno = EINVAL. getenv() would just return NULL. POSIX says about names: 1) "names shall not contain the character '='" and "points to an empty string". 2) "Other characters may be permitted by an implementation; applications shall tolerate the presence of such names." So I see no point to treat ' ' some special way. -- http://ache.pp.ru/