From owner-svn-src-all@FreeBSD.ORG Sun Dec 6 23:05:18 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 52DBE106566B; Sun, 6 Dec 2009 23:05:18 +0000 (UTC) (envelope-from scf@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 2858C8FC08; Sun, 6 Dec 2009 23:05:18 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nB6N5Ibu034466; Sun, 6 Dec 2009 23:05:18 GMT (envelope-from scf@svn.freebsd.org) Received: (from scf@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nB6N5I2S034464; Sun, 6 Dec 2009 23:05:18 GMT (envelope-from scf@svn.freebsd.org) Message-Id: <200912062305.nB6N5I2S034464@svn.freebsd.org> From: Sean Farley Date: Sun, 6 Dec 2009 23:05:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200190 - head/lib/libc/stdlib X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Dec 2009 23:05:18 -0000 Author: scf Date: Sun Dec 6 23:05:17 2009 New Revision: 200190 URL: http://svn.freebsd.org/changeset/base/200190 Log: Improve the comment within getenv() explaining the search order it takes to find a variable. Include a note that it must not cause the internal environment to be generated since malloc() depends upon getenv(). To call malloc() would create a circular dependency. Recommended by: green Approved by: jilles MFC after: 1 week Modified: head/lib/libc/stdlib/getenv.c Modified: head/lib/libc/stdlib/getenv.c ============================================================================== --- head/lib/libc/stdlib/getenv.c Sun Dec 6 22:14:58 2009 (r200189) +++ head/lib/libc/stdlib/getenv.c Sun Dec 6 23:05:17 2009 (r200190) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2007-2008 Sean C. Farley + * Copyright (c) 2007-2009 Sean C. Farley * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -160,7 +160,7 @@ __findenv(const char *name, size_t nameL /* * Find environment variable from end of array (more likely to be - * active). A variable created by putenv is always active or it is not + * active). A variable created by putenv is always active, or it is not * tracked in the array. */ for (ndx = *envNdx; ndx >= 0; ndx--) @@ -426,13 +426,14 @@ getenv(const char *name) } /* - * An empty environment (environ or its first value) regardless if - * environ has been copied before will return a NULL. + * Variable search order: + * 1. Check for an empty environ. This allows an application to clear + * the environment. + * 2. Search the external environ array. + * 3. Search the internal environment. * - * If the environment is not empty, find an environment variable via - * environ if environ has not been copied via an *env() call or been - * replaced by a running program, otherwise, use the rebuilt - * environment. + * Since malloc() depends upon getenv(), getenv() must never cause the + * internal environment storage to be generated. */ if (environ == NULL || environ[0] == NULL) return (NULL);