getenv.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at http://curl.haxx.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. * $Id: getenv.c,v 1.23 2004/01/29 13:56:45 bagder Exp $
  22. ***************************************************************************/
  23. #include "setup.h"
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #ifdef WIN32
  28. #include <windows.h>
  29. #endif
  30. #ifdef VMS
  31. #include <unixlib.h>
  32. #endif
  33. #include <curl/curl.h>
  34. #ifdef CURLDEBUG
  35. #include "memdebug.h"
  36. #endif
  37. static
  38. char *GetEnv(const char *variable)
  39. {
  40. #ifdef WIN32
  41. /* This shit requires windows.h (HUGE) to be included */
  42. char env[MAX_PATH]; /* MAX_PATH is from windef.h */
  43. char *temp = getenv(variable);
  44. env[0] = '\0';
  45. if (temp != NULL)
  46. ExpandEnvironmentStrings(temp, env, sizeof(env));
  47. #else
  48. #ifdef VMS
  49. char *env = getenv(variable);
  50. if (env && strcmp("HOME",variable) == 0) {
  51. env = decc$translate_vms(env);
  52. }
  53. #else
  54. /* no length control */
  55. char *env = getenv(variable);
  56. #endif
  57. #endif
  58. return (env && env[0])?strdup(env):NULL;
  59. }
  60. char *curl_getenv(const char *v)
  61. {
  62. return GetEnv(v);
  63. }