home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tkisrc04.zip / tcl / os2 / tclOS2Env.c < prev    next >
C/C++ Source or Header  |  1998-08-07  |  1KB  |  57 lines

  1. /* 
  2.  * tclOS2Env.c --
  3.  *
  4.  *    This file defines the TclOS2SetSystemEnv function.
  5.  *
  6.  * Copyright (c) 1996-1997 Illya Vaes
  7.  *
  8.  * See the file "license.terms" for information on usage and redistribution
  9.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  10.  */
  11.  
  12.  
  13. #include "tclInt.h"
  14. #include "tclPort.h"
  15.  
  16. /*
  17.  *----------------------------------------------------------------------
  18.  *
  19.  * TclSetSystemEnv --
  20.  *
  21.  *    Set an environment variable.
  22.  *
  23.  * Results:
  24.  *    0 on sucess, -1 on failure.
  25.  *
  26.  * Side effects:
  27.  *    None.
  28.  *
  29.  *----------------------------------------------------------------------
  30.  */
  31. int
  32. TclSetSystemEnv( const char *variable, const char *value )
  33. {
  34.     char *string;
  35.     int ret;
  36.  
  37.     string= malloc(strlen(variable)+1+strlen(value)+1);
  38.     if (string == (char *)NULL) return -1;
  39.     ret = sprintf(string, "%s=%s", variable, value);
  40.     if (ret == 0 || ret == EOF) {
  41. #ifdef DEBUG
  42.         printf("TclSetSystemEnv: sprintf \"%s=%s\" returns %d\n", variable,
  43.                value, ret);
  44.         fflush(stdout);
  45. #endif
  46.         free(string);
  47.         return -1;
  48.     }
  49.     ret= putenv(string);
  50.     /* String may NOT be freed or reused */
  51. #ifdef DEBUG
  52.     printf("putenv \"%s\" returns %d\n", string, ret);
  53.     fflush(stdout);
  54. #endif
  55.     return ret;
  56. }
  57.