~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/msvcrt/environ.c

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /*
  2  * msvcrt.dll environment functions
  3  *
  4  * Copyright 1996,1998 Marcus Meissner
  5  * Copyright 1996 Jukka Iivonen
  6  * Copyright 1997,2000 Uwe Bonnes
  7  * Copyright 2000 Jon Griffiths
  8  *
  9  * This library is free software; you can redistribute it and/or
 10  * modify it under the terms of the GNU Lesser General Public
 11  * License as published by the Free Software Foundation; either
 12  * version 2.1 of the License, or (at your option) any later version.
 13  *
 14  * This library is distributed in the hope that it will be useful,
 15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17  * Lesser General Public License for more details.
 18  *
 19  * You should have received a copy of the GNU Lesser General Public
 20  * License along with this library; if not, write to the Free Software
 21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 22  */
 23 #include "wine/unicode.h"
 24 #include "msvcrt.h"
 25 #include "wine/debug.h"
 26 
 27 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
 28 
 29 /*********************************************************************
 30  *              getenv (MSVCRT.@)
 31  */
 32 char * CDECL MSVCRT_getenv(const char *name)
 33 {
 34     char **environ;
 35     unsigned int length=strlen(name);
 36 
 37     for (environ = *__p__environ(); *environ; environ++)
 38     {
 39         char *str = *environ;
 40         char *pos = strchr(str,'=');
 41         if (pos && ((pos - str) == length) && !strncasecmp(str,name,length))
 42         {
 43             TRACE("(%s): got %s\n", debugstr_a(name), debugstr_a(pos + 1));
 44             return pos + 1;
 45         }
 46     }
 47     return NULL;
 48 }
 49 
 50 /*********************************************************************
 51  *              _wgetenv (MSVCRT.@)
 52  */
 53 MSVCRT_wchar_t * CDECL _wgetenv(const MSVCRT_wchar_t *name)
 54 {
 55     MSVCRT_wchar_t **environ;
 56     unsigned int length=strlenW(name);
 57 
 58     for (environ = *__p__wenviron(); *environ; environ++)
 59     {
 60         MSVCRT_wchar_t *str = *environ;
 61         MSVCRT_wchar_t *pos = strchrW(str,'=');
 62         if (pos && ((pos - str) == length) && !strncmpiW(str,name,length))
 63         {
 64             TRACE("(%s): got %s\n", debugstr_w(name), debugstr_w(pos + 1));
 65             return pos + 1;
 66         }
 67     }
 68     return NULL;
 69 }
 70 
 71 /*********************************************************************
 72  *              _putenv (MSVCRT.@)
 73  */
 74 int CDECL _putenv(const char *str)
 75 {
 76  char *name, *value;
 77  char *dst;
 78  int ret;
 79 
 80  TRACE("%s\n", debugstr_a(str));
 81 
 82  if (!str)
 83    return -1;
 84    
 85  name = HeapAlloc(GetProcessHeap(), 0, strlen(str) + 1);
 86  if (!name)
 87    return -1;
 88  dst = name;
 89  while (*str && *str != '=')
 90   *dst++ = *str++;
 91  if (!*str++)
 92  {
 93    ret = -1;
 94    goto finish;
 95  }
 96  *dst++ = '\0';
 97  value = dst;
 98  while (*str)
 99   *dst++ = *str++;
100  *dst = '\0';
101 
102  ret = SetEnvironmentVariableA(name, value[0] ? value : NULL) ? 0 : -1;
103 
104  /* _putenv returns success on deletion of nonexistent variable, unlike [Rtl]SetEnvironmentVariable */
105  if ((ret == -1) && (GetLastError() == ERROR_ENVVAR_NOT_FOUND)) ret = 0;
106 
107  /* Update the __p__environ array only when already initialized */
108  if (MSVCRT__environ)
109    MSVCRT__environ = msvcrt_SnapshotOfEnvironmentA(MSVCRT__environ);
110  if (MSVCRT__wenviron)
111    MSVCRT__wenviron = msvcrt_SnapshotOfEnvironmentW(MSVCRT__wenviron);
112    
113 finish:
114  HeapFree(GetProcessHeap(), 0, name);
115  return ret;
116 }
117 
118 /*********************************************************************
119  *              _wputenv (MSVCRT.@)
120  */
121 int CDECL _wputenv(const MSVCRT_wchar_t *str)
122 {
123  MSVCRT_wchar_t *name, *value;
124  MSVCRT_wchar_t *dst;
125  int ret;
126 
127  TRACE("%s\n", debugstr_w(str));
128 
129  if (!str)
130    return -1;
131  name = HeapAlloc(GetProcessHeap(), 0, (strlenW(str) + 1) * sizeof(MSVCRT_wchar_t));
132  if (!name)
133    return -1;
134  dst = name;
135  while (*str && *str != '=')
136   *dst++ = *str++;
137  if (!*str++)
138  {
139    ret = -1;
140    goto finish;
141  }
142  *dst++ = 0;
143  value = dst;
144  while (*str)
145   *dst++ = *str++;
146  *dst = 0;
147 
148  ret = SetEnvironmentVariableW(name, value[0] ? value : NULL) ? 0 : -1;
149 
150  /* _putenv returns success on deletion of nonexistent variable, unlike [Rtl]SetEnvironmentVariable */
151  if ((ret == -1) && (GetLastError() == ERROR_ENVVAR_NOT_FOUND)) ret = 0;
152 
153  /* Update the __p__environ array only when already initialized */
154  if (MSVCRT__environ)
155    MSVCRT__environ = msvcrt_SnapshotOfEnvironmentA(MSVCRT__environ);
156  if (MSVCRT__wenviron)
157    MSVCRT__wenviron = msvcrt_SnapshotOfEnvironmentW(MSVCRT__wenviron);
158 
159 finish:
160  HeapFree(GetProcessHeap(), 0, name);
161  return ret;
162 }
163 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.