delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1999/08/09/09:57:14

Message-Id: <199908091237.MAA44712@out4.ibm.net>
From: "Mark E." <snowball3 AT bigfoot DOT com>
To: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>, djgpp-workers AT delorie DOT com
Date: Mon, 9 Aug 1999 08:38:02 -0400
MIME-Version: 1.0
Subject: Re: suggestion for getenv.c
References: <199908082020 DOT UAA80886 AT out1 DOT ibm DOT net>
In-reply-to: <Pine.SUN.3.91.990809111651.19120F-100000@is>
X-mailer: Pegasus Mail for Win32 (v3.11)
Reply-To: djgpp-workers AT delorie DOT com

> Why should we silently ignore a NULL pointer?  If anything, we should
> set errno to EFAULT.  `environ' being NULL is a valid situation, but
> passing a NULL `name' is not.
> 

Fair enough. Here's a revised version:

*** src/libc/ansi/stdlib/getenv.c.orig	Fri Nov 24 22:21:18 1995
--- src/libc/ansi/stdlib/getenv.c	Mon Aug  9 08:34:30 1999
***************
*** 1,6 ****
--- 1,8 ----
+ /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  #include <stdlib.h>
  #include <string.h>
+ #include <errno.h>
  
  extern char **environ;
  
*************** char *
*** 8,13 ****
--- 10,21 ----
  getenv(const char *name)
  {
    int i;
+ 
+   if (name == 0)
+   {
+     errno = EFAULT;
+     return 0;
+   }
  
    if (environ == 0)
      return 0;
 


--- 
Mark Elbrecht, snowball3 AT bigfoot DOT com
http://snowball.frogspace.net/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019