getenv.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*****************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 2000, Daniel Stenberg, <[email protected]>, et al.
  9. *
  10. * In order to be useful for every potential user, curl and libcurl are
  11. * dual-licensed under the MPL and the MIT/X-derivate licenses.
  12. *
  13. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  14. * copies of the Software, and permit persons to whom the Software is
  15. * furnished to do so, under the terms of the MPL or the MIT/X-derivate
  16. * licenses. You may pick one of these licenses.
  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. env = decc$translate_vms(env);
  51. }
  52. #else
  53. /* no length control */
  54. char *env = getenv(variable);
  55. #endif
  56. #endif
  57. return (env && env[0])?strdup(env):NULL;
  58. }
  59. char *curl_getenv(const char *v)
  60. {
  61. return GetEnv(v);
  62. }
  63. /*
  64. * local variables:
  65. * eval: (load-file "../curl-mode.el")
  66. * end:
  67. * vim600: fdm=marker
  68. * vim: et sw=2 ts=2 sts=2 tw=78
  69. */