home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / stdlib / unsetenv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-22  |  1.8 KB  |  76 lines

  1. /* 
  2.  * unsetenv.c --
  3.  *
  4.  *    Procedure to simulate cshell unsetenv call.
  5.  *
  6.  * Copyright (C) 1986 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/unsetenv.c,v 1.5 89/03/22 00:47:37 rab Exp $ SPRITE (Berkeley)";
  18. #endif /* not lint */
  19.  
  20. #include <sprite.h>
  21. #include <stdlib.h>
  22.  
  23. extern char **environ;
  24. extern char *malloc();
  25.  
  26.  
  27. /*
  28.  *----------------------------------------------------------------------
  29.  *
  30.  * unsetenv --
  31.  *
  32.  *    Unsets the given variable.  Note: taken from MH, temporary, doesn't
  33.  *      free space.
  34.  *
  35.  * Results:
  36.  *    None.
  37.  *
  38.  * Side effects:
  39.  *    "Name" will no longer exist as an environment variable.
  40.  *
  41.  *----------------------------------------------------------------------
  42.  */
  43.  
  44. void
  45. unsetenv(name)
  46.     char    *name;    /* Name of variable. */
  47. {
  48.     register char **envPtr;
  49.     register char **newEnvPtr;
  50.     register char *charPtr;
  51.     register char *namePtr;
  52.     register Boolean found = FALSE;
  53.  
  54.     for (envPtr = environ; *envPtr != NULL; envPtr++) {
  55.     for (charPtr = *envPtr, namePtr = name;
  56.          *charPtr == *namePtr; namePtr++) {
  57.          charPtr++;
  58.          if (*charPtr == '=') {
  59.          found = TRUE;
  60.          break;
  61.          }
  62.      }
  63.     if (found) {
  64.         break;
  65.     }
  66.     }
  67.     if (!found) {
  68.     return;
  69.     }
  70.     for (newEnvPtr = envPtr + 1; *newEnvPtr; newEnvPtr++) {
  71.     }
  72.     newEnvPtr--;
  73.     *envPtr = *newEnvPtr;
  74.     *newEnvPtr = NULL;
  75. }
  76.