diff options
author | Angelo Mantellini (manangel) <angelo.mantellini@irt-systemx.fr> | 2017-04-25 21:17:37 +0200 |
---|---|---|
committer | Angelo Mantellini (manangel) <angelo.mantellini@irt-systemx.fr> | 2017-04-25 23:01:06 +0200 |
commit | 208d43c7988c527691b663e4e00b56b42cc19277 (patch) | |
tree | e26df3383b4256bcde3c95cc4ce32177c8dd744b /external/libcurl_android/jni/libcurl/src/tool_dirhie.c | |
parent | 4ff32ec79cf0ba8ddb8c46f2f36adce379819643 (diff) |
correction link libraries libcurl
Change-Id: I8be291ac6b9ec15f0f7bbaa8b434da9d319ae389
Signed-off-by: Angelo Mantellini (manangel) <angelo.mantellini@irt-systemx.fr>
Diffstat (limited to 'external/libcurl_android/jni/libcurl/src/tool_dirhie.c')
-rwxr-xr-x | external/libcurl_android/jni/libcurl/src/tool_dirhie.c | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/external/libcurl_android/jni/libcurl/src/tool_dirhie.c b/external/libcurl_android/jni/libcurl/src/tool_dirhie.c new file mode 100755 index 00000000..5965f7a7 --- /dev/null +++ b/external/libcurl_android/jni/libcurl/src/tool_dirhie.c @@ -0,0 +1,147 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ +#include "tool_setup.h" + +#include <sys/stat.h> + +#ifdef WIN32 +# include <direct.h> +#endif + +#define ENABLE_CURLX_PRINTF +/* use our own printf() functions */ +#include "curlx.h" + +#include "tool_dirhie.h" + +#include "memdebug.h" /* keep this as LAST include */ + +#ifdef NETWARE +# ifndef __NOVELL_LIBC__ +# define mkdir mkdir_510 +# endif +#endif + +#ifdef WIN32 +# define mkdir(x,y) (mkdir)((x)) +# ifndef __POCC__ +# define F_OK 0 +# endif +#endif + +static void show_dir_errno(FILE *errors, const char *name) +{ + switch(ERRNO) { +#ifdef EACCES + case EACCES: + fprintf(errors, "You don't have permission to create %s.\n", name); + break; +#endif +#ifdef ENAMETOOLONG + case ENAMETOOLONG: + fprintf(errors, "The directory name %s is too long.\n", name); + break; +#endif +#ifdef EROFS + case EROFS: + fprintf(errors, "%s resides on a read-only file system.\n", name); + break; +#endif +#ifdef ENOSPC + case ENOSPC: + fprintf(errors, "No space left on the file system that will " + "contain the directory %s.\n", name); + break; +#endif +#ifdef EDQUOT + case EDQUOT: + fprintf(errors, "Cannot create directory %s because you " + "exceeded your quota.\n", name); + break; +#endif + default : + fprintf(errors, "Error creating directory %s.\n", name); + break; + } +} + +/* + * Create the needed directory hierarchy recursively in order to save + * multi-GETs in file output, ie: + * curl "http://my.site/dir[1-5]/file[1-5].txt" -o "dir#1/file#2.txt" + * should create all the dir* automagically + */ + +CURLcode create_dir_hierarchy(const char *outfile, FILE *errors) +{ + char *tempdir; + char *tempdir2; + char *outdup; + char *dirbuildup; + CURLcode result = CURLE_OK; + size_t outlen; + + outlen = strlen(outfile); + outdup = strdup(outfile); + if(!outdup) + return CURLE_OUT_OF_MEMORY; + + dirbuildup = malloc(outlen + 1); + if(!dirbuildup) { + Curl_safefree(outdup); + return CURLE_OUT_OF_MEMORY; + } + dirbuildup[0] = '\0'; + + tempdir = strtok(outdup, DIR_CHAR); + + while(tempdir != NULL) { + tempdir2 = strtok(NULL, DIR_CHAR); + /* since strtok returns a token for the last word even + if not ending with DIR_CHAR, we need to prune it */ + if(tempdir2 != NULL) { + size_t dlen = strlen(dirbuildup); + if(dlen) + snprintf(&dirbuildup[dlen], outlen - dlen, "%s%s", DIR_CHAR, tempdir); + else { + if(0 != strncmp(outdup, DIR_CHAR, 1)) + strcpy(dirbuildup, tempdir); + else + snprintf(dirbuildup, outlen, "%s%s", DIR_CHAR, tempdir); + } + if(access(dirbuildup, F_OK) == -1) { + if(-1 == mkdir(dirbuildup,(mode_t)0000750)) { + show_dir_errno(errors, dirbuildup); + result = CURLE_WRITE_ERROR; + break; /* get out of loop */ + } + } + } + tempdir = tempdir2; + } + + Curl_safefree(dirbuildup); + Curl_safefree(outdup); + + return result; +} + |