diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-04-27 01:30:12 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-04-27 01:30:12 +0200 |
commit | 25c2e03228e00f577fac4a52079c601010df4f15 (patch) | |
tree | 7ac888aa635be14d39e93aa6688dd816b9d4a723 /src/main.c | |
parent | 9b2a563b4931ca39cd6dd14bf85cda627714a4b2 (diff) | |
download | blogc-25c2e03228e00f577fac4a52079c601010df4f15.tar.gz blogc-25c2e03228e00f577fac4a52079c601010df4f15.tar.bz2 blogc-25c2e03228e00f577fac4a52079c601010df4f15.zip |
Revert "main: loader: use file utils from squareball"
This reverts commit c7b4bc4d64a3ce669e54b7c7dae87527d9ee3123.
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 52 |
1 files changed, 36 insertions, 16 deletions
@@ -18,10 +18,6 @@ #include <sys/types.h> #endif /* HAVE_SYS_TYPES_H */ -#ifdef HAVE_LIBGEN_H -#include <libgen.h> -#endif /* HAVE_LIBGEN_H */ - #include <errno.h> #include <locale.h> #include <stdbool.h> @@ -72,6 +68,41 @@ blogc_print_usage(void) } +static void +blogc_mkdir_recursive(const char *filename) +{ + char *fname = sb_strdup(filename); + for (char *tmp = fname; *tmp != '\0'; tmp++) { + if (*tmp != '/' && *tmp != '\\') + continue; +#if defined(HAVE_SYS_STAT_H) && defined(HAVE_SYS_TYPES_H) + char bkp = *tmp; + *tmp = '\0'; + if ((strlen(fname) > 0) && +#if defined(WIN32) || defined(_WIN32) + (-1 == mkdir(fname)) && +#else + (-1 == mkdir(fname, 0777)) && +#endif + (errno != EEXIST)) + { + fprintf(stderr, "blogc: error: failed to create output " + "directory (%s): %s\n", fname, strerror(errno)); + free(fname); + exit(2); + } + *tmp = bkp; +#else + // FIXME: show this warning only if actually trying to create a directory. + fprintf(stderr, "blogc: warning: can't create output directories " + "for your platform. please create the directories yourself.\n"); + break; +#endif + } + free(fname); +} + + int main(int argc, char **argv) { @@ -221,18 +252,7 @@ main(int argc, char **argv) FILE *fp = stdout; if (!write_to_stdout) { - -#ifdef HAVE_LIBGEN_H - char *_output = sb_strdup(output); - sb_mkdir_recursive(dirname(_output), &err); - free(_output); - if (err != NULL) { - blogc_error_print(err); - rv = 2; - goto cleanup4; - } -#endif - + blogc_mkdir_recursive(output); fp = fopen(output, "w"); if (fp == NULL) { fprintf(stderr, "blogc: error: failed to open output file (%s): %s\n", |