Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "tool_setup.h"
00023
00024 #include <sys/stat.h>
00025
00026 #ifdef WIN32
00027 # include <direct.h>
00028 #endif
00029
00030 #define ENABLE_CURLX_PRINTF
00031
00032 #include "curlx.h"
00033
00034 #include "tool_dirhie.h"
00035
00036 #include "memdebug.h"
00037
00038 #ifdef NETWARE
00039 # ifndef __NOVELL_LIBC__
00040 # define mkdir mkdir_510
00041 # endif
00042 #endif
00043
00044 #ifdef WIN32
00045 # define mkdir(x,y) (mkdir)((x))
00046 # ifndef __POCC__
00047 # define F_OK 0
00048 # endif
00049 #endif
00050
00051 static void show_dir_errno(FILE *errors, const char *name)
00052 {
00053 switch(ERRNO) {
00054 #ifdef EACCES
00055 case EACCES:
00056 fprintf(errors, "You don't have permission to create %s.\n", name);
00057 break;
00058 #endif
00059 #ifdef ENAMETOOLONG
00060 case ENAMETOOLONG:
00061 fprintf(errors, "The directory name %s is too long.\n", name);
00062 break;
00063 #endif
00064 #ifdef EROFS
00065 case EROFS:
00066 fprintf(errors, "%s resides on a read-only file system.\n", name);
00067 break;
00068 #endif
00069 #ifdef ENOSPC
00070 case ENOSPC:
00071 fprintf(errors, "No space left on the file system that will "
00072 "contain the directory %s.\n", name);
00073 break;
00074 #endif
00075 #ifdef EDQUOT
00076 case EDQUOT:
00077 fprintf(errors, "Cannot create directory %s because you "
00078 "exceeded your quota.\n", name);
00079 break;
00080 #endif
00081 default :
00082 fprintf(errors, "Error creating directory %s.\n", name);
00083 break;
00084 }
00085 }
00086
00087
00088
00089
00090
00091
00092
00093
00094 #ifdef WIN32
00095
00096 #define PATH_DELIMITERS "\\/"
00097 #else
00098 #define PATH_DELIMITERS DIR_CHAR
00099 #endif
00100
00101
00102 CURLcode create_dir_hierarchy(const char *outfile, FILE *errors)
00103 {
00104 char *tempdir;
00105 char *tempdir2;
00106 char *outdup;
00107 char *dirbuildup;
00108 CURLcode result = CURLE_OK;
00109 size_t outlen;
00110
00111 outlen = strlen(outfile);
00112 outdup = strdup(outfile);
00113 if(!outdup)
00114 return CURLE_OUT_OF_MEMORY;
00115
00116 dirbuildup = malloc(outlen + 1);
00117 if(!dirbuildup) {
00118 Curl_safefree(outdup);
00119 return CURLE_OUT_OF_MEMORY;
00120 }
00121 dirbuildup[0] = '\0';
00122
00123
00124
00125 tempdir = strtok(outdup, PATH_DELIMITERS);
00126
00127 while(tempdir != NULL) {
00128 tempdir2 = strtok(NULL, PATH_DELIMITERS);
00129
00130
00131 if(tempdir2 != NULL) {
00132 size_t dlen = strlen(dirbuildup);
00133 if(dlen)
00134 snprintf(&dirbuildup[dlen], outlen - dlen, "%s%s", DIR_CHAR, tempdir);
00135 else {
00136 if(outdup == tempdir)
00137
00138 strcpy(dirbuildup, tempdir);
00139 else
00140 snprintf(dirbuildup, outlen, "%s%s", DIR_CHAR, tempdir);
00141 }
00142 if(access(dirbuildup, F_OK) == -1) {
00143 if(-1 == mkdir(dirbuildup, (mode_t)0000750)) {
00144 show_dir_errno(errors, dirbuildup);
00145 result = CURLE_WRITE_ERROR;
00146 break;
00147 }
00148 }
00149 }
00150 tempdir = tempdir2;
00151 }
00152
00153 Curl_safefree(dirbuildup);
00154 Curl_safefree(outdup);
00155
00156 return result;
00157 }
00158