诸暨麻将添加redis
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

96 wiersze
2.7 KiB

  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2012, 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. ***************************************************************************/
  22. #include "tool_setup.h"
  23. #ifdef HAVE_PWD_H
  24. # include <pwd.h>
  25. #endif
  26. #include "tool_homedir.h"
  27. #include "memdebug.h" /* keep this as LAST include */
  28. static char *GetEnv(const char *variable, char do_expand)
  29. {
  30. char *env = NULL;
  31. #ifdef WIN32
  32. char buf1[1024], buf2[1024];
  33. DWORD rc;
  34. /* Don't use getenv(); it doesn't find variable added after program was
  35. * started. Don't accept truncated results (i.e. rc >= sizeof(buf1)). */
  36. rc = GetEnvironmentVariable(variable, buf1, sizeof(buf1));
  37. if(rc > 0 && rc < sizeof(buf1)) {
  38. env = buf1;
  39. variable = buf1;
  40. }
  41. if(do_expand && strchr(variable,'%')) {
  42. /* buf2 == variable if not expanded */
  43. rc = ExpandEnvironmentStrings (variable, buf2, sizeof(buf2));
  44. if(rc > 0 && rc < sizeof(buf2) &&
  45. !strchr(buf2,'%')) /* no vars still unexpanded */
  46. env = buf2;
  47. }
  48. #else
  49. (void)do_expand;
  50. /* no length control */
  51. env = getenv(variable);
  52. #endif
  53. return (env && env[0]) ? strdup(env) : NULL;
  54. }
  55. /* return the home directory of the current user as an allocated string */
  56. char *homedir(void)
  57. {
  58. char *home;
  59. home = GetEnv("CURL_HOME", FALSE);
  60. if(home)
  61. return home;
  62. home = GetEnv("HOME", FALSE);
  63. if(home)
  64. return home;
  65. #if defined(HAVE_GETPWUID) && defined(HAVE_GETEUID)
  66. {
  67. struct passwd *pw = getpwuid(geteuid());
  68. if(pw) {
  69. home = pw->pw_dir;
  70. if(home && home[0])
  71. home = strdup(home);
  72. else
  73. home = NULL;
  74. }
  75. }
  76. #endif /* PWD-stuff */
  77. #ifdef WIN32
  78. home = GetEnv("APPDATA", TRUE);
  79. if(!home)
  80. home = GetEnv("%USERPROFILE%\\Application Data", TRUE); /* Normally only
  81. on Win-2K/XP */
  82. #endif /* WIN32 */
  83. return home;
  84. }