getenv.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2002, Daniel Stenberg, <[email protected]>, 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$
  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. #ifdef MALLOCDEBUG
  34. #include "memdebug.h"
  35. #endif
  36. static
  37. char *GetEnv(const char *variable)
  38. {
  39. #ifdef WIN32
  40. /* This shit requires windows.h (HUGE) to be included */
  41. char env[MAX_PATH]; /* MAX_PATH is from windef.h */
  42. char *temp = getenv(variable);
  43. env[0] = '\0';
  44. if (temp != NULL)
  45. ExpandEnvironmentStrings(temp, env, sizeof(env));
  46. #else
  47. #ifdef VMS
  48. char *env = getenv(variable);
  49. if (env && strcmp("HOME",variable) == 0) {
  50. /* VMS does not work because of warning on icc */
  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. }
  64. /*
  65. * local variables:
  66. * eval: (load-file "../curl-mode.el")
  67. * end:
  68. * vim600: fdm=marker
  69. * vim: et sw=2 ts=2 sts=2 tw=78
  70. */