诸暨麻将添加redis
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

148 lines
3.8 KiB

  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2013, 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. #include <sys/stat.h>
  24. #ifdef WIN32
  25. # include <direct.h>
  26. #endif
  27. #define ENABLE_CURLX_PRINTF
  28. /* use our own printf() functions */
  29. #include "curlx.h"
  30. #include "tool_dirhie.h"
  31. #include "memdebug.h" /* keep this as LAST include */
  32. #ifdef NETWARE
  33. # ifndef __NOVELL_LIBC__
  34. # define mkdir mkdir_510
  35. # endif
  36. #endif
  37. #ifdef WIN32
  38. # define mkdir(x,y) (mkdir)((x))
  39. # ifndef __POCC__
  40. # define F_OK 0
  41. # endif
  42. #endif
  43. static void show_dir_errno(FILE *errors, const char *name)
  44. {
  45. switch(ERRNO) {
  46. #ifdef EACCES
  47. case EACCES:
  48. fprintf(errors, "You don't have permission to create %s.\n", name);
  49. break;
  50. #endif
  51. #ifdef ENAMETOOLONG
  52. case ENAMETOOLONG:
  53. fprintf(errors, "The directory name %s is too long.\n", name);
  54. break;
  55. #endif
  56. #ifdef EROFS
  57. case EROFS:
  58. fprintf(errors, "%s resides on a read-only file system.\n", name);
  59. break;
  60. #endif
  61. #ifdef ENOSPC
  62. case ENOSPC:
  63. fprintf(errors, "No space left on the file system that will "
  64. "contain the directory %s.\n", name);
  65. break;
  66. #endif
  67. #ifdef EDQUOT
  68. case EDQUOT:
  69. fprintf(errors, "Cannot create directory %s because you "
  70. "exceeded your quota.\n", name);
  71. break;
  72. #endif
  73. default :
  74. fprintf(errors, "Error creating directory %s.\n", name);
  75. break;
  76. }
  77. }
  78. /*
  79. * Create the needed directory hierarchy recursively in order to save
  80. * multi-GETs in file output, ie:
  81. * curl "http://my.site/dir[1-5]/file[1-5].txt" -o "dir#1/file#2.txt"
  82. * should create all the dir* automagically
  83. */
  84. CURLcode create_dir_hierarchy(const char *outfile, FILE *errors)
  85. {
  86. char *tempdir;
  87. char *tempdir2;
  88. char *outdup;
  89. char *dirbuildup;
  90. CURLcode result = CURLE_OK;
  91. size_t outlen;
  92. outlen = strlen(outfile);
  93. outdup = strdup(outfile);
  94. if(!outdup)
  95. return CURLE_OUT_OF_MEMORY;
  96. dirbuildup = malloc(outlen + 1);
  97. if(!dirbuildup) {
  98. Curl_safefree(outdup);
  99. return CURLE_OUT_OF_MEMORY;
  100. }
  101. dirbuildup[0] = '\0';
  102. tempdir = strtok(outdup, DIR_CHAR);
  103. while(tempdir != NULL) {
  104. tempdir2 = strtok(NULL, DIR_CHAR);
  105. /* since strtok returns a token for the last word even
  106. if not ending with DIR_CHAR, we need to prune it */
  107. if(tempdir2 != NULL) {
  108. size_t dlen = strlen(dirbuildup);
  109. if(dlen)
  110. snprintf(&dirbuildup[dlen], outlen - dlen, "%s%s", DIR_CHAR, tempdir);
  111. else {
  112. if(0 != strncmp(outdup, DIR_CHAR, 1))
  113. strcpy(dirbuildup, tempdir);
  114. else
  115. snprintf(dirbuildup, outlen, "%s%s", DIR_CHAR, tempdir);
  116. }
  117. if(access(dirbuildup, F_OK) == -1) {
  118. if(-1 == mkdir(dirbuildup,(mode_t)0000750)) {
  119. show_dir_errno(errors, dirbuildup);
  120. result = CURLE_WRITE_ERROR;
  121. break; /* get out of loop */
  122. }
  123. }
  124. }
  125. tempdir = tempdir2;
  126. }
  127. Curl_safefree(dirbuildup);
  128. Curl_safefree(outdup);
  129. return result;
  130. }