diff --git a/src/build/util.c b/src/build/util.c index aacf33927..012c557da 100644 --- a/src/build/util.c +++ b/src/build/util.c @@ -19,11 +19,12 @@ #include #include #include -#include #include #include #include +#include #include +#include #include #include #include diff --git a/src/gamecode/study.c b/src/gamecode/study.c index 36fda0217..2fbcb270e 100644 --- a/src/gamecode/study.c +++ b/src/gamecode/study.c @@ -589,7 +589,7 @@ learn_cmd(unit * u, order * ord) struct building * b = inside_building(u); const struct building_type * btype = b?b->type:NULL; - if (btype == bt_find("academy")) { + if (btype && btype == bt_find("academy")) { studycost = MAX(50, studycost * 2); } } diff --git a/src/kernel/battle.c b/src/kernel/battle.c index 0aaa0e840..3d8747c61 100644 --- a/src/kernel/battle.c +++ b/src/kernel/battle.c @@ -59,6 +59,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include #include @@ -3575,7 +3576,7 @@ make_battle(region * r) char zText[MAX_PATH]; char zFilename[MAX_PATH]; sprintf(zText, "%s/battles", basepath()); - makedir(zText, 0700); + os_mkdir(zText, 0700); sprintf(zFilename, "%s/battle-%d-%s.log", zText, obs_count, simplename(r)); bdebug = fopen(zFilename, "w"); if (!bdebug) log_error(("battles cannot be debugged\n")); diff --git a/src/kernel/reports.c b/src/kernel/reports.c index c22c5f392..0cca313b4 100644 --- a/src/kernel/reports.c +++ b/src/kernel/reports.c @@ -51,6 +51,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include /* libc includes */ @@ -1491,7 +1492,7 @@ init_reports(void) if (stat(reportpath(), &st)==0) return 0; } #endif - if (makedir(reportpath(), 0700)!=0) { + if (os_mkdir(reportpath(), 0700)!=0) { if (errno!=EEXIST) { perror("could not create reportpath"); return -1; diff --git a/src/kernel/save.c b/src/kernel/save.c index 17a17b685..7dedc93b1 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -61,6 +61,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include #include @@ -1683,7 +1684,11 @@ writegame(const char *filename, int mode) store->encoding = enc_gamedata; if (store->open(store, path, IO_WRITE)!=0) { - return -1; + int err = os_mkdir(datapath(), 0700); + if (err) return err; + if (store->open(store, path, IO_WRITE)!=0) { + return -1; + } } /* globale Variablen */ diff --git a/src/platform.h b/src/platform.h index e8b988885..96903dde7 100644 --- a/src/platform.h +++ b/src/platform.h @@ -120,19 +120,12 @@ typedef struct stat stat_type; # define HAVE_SNPRINTF #ifdef _POSIX_SOURCE /* MINGW doesn't seem to have these */ # define HAVE_EXECINFO -# define HAVE_MKDIR_WITH_PERMISSION # define HAVE_SIGACTION # define HAVE_LINK # define HAVE_SLEEP #endif #endif -/* egcpp 4 dos */ -#ifdef MSDOS -# include -# define HAVE_MKDIR_WITH_PERMISSION -#endif - /* TinyCC */ #ifdef TINYCC # undef HAVE_INLINE @@ -211,15 +204,6 @@ typedef struct _stat stat_type; # endif #endif -#ifdef HAVE_MKDIR_WITH_PERMISSION -# define makedir(d, p) mkdir(d, p) -#elif defined(HAVE_MKDIR_WITHOUT_PERMISSION) -# define makedir(d, p) mkdir(d) -#elif defined(HAVE__MKDIR_WITHOUT_PERMISSION) -_CRTIMP int __cdecl _mkdir(const char *); -# define makedir(d, p) _mkdir(d) -#endif - #ifndef HAVE_STRDUP extern char * strdup(const char *s); #endif diff --git a/src/util.vcxproj b/src/util.vcxproj index 02c556a66..027e10ae6 100644 --- a/src/util.vcxproj +++ b/src/util.vcxproj @@ -107,6 +107,7 @@ + @@ -142,6 +143,7 @@ + diff --git a/src/util.vcxproj.filters b/src/util.vcxproj.filters index 726f4856e..f1e5a7d17 100644 --- a/src/util.vcxproj.filters +++ b/src/util.vcxproj.filters @@ -110,6 +110,9 @@ Header Files + + Source Files + @@ -208,5 +211,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/src/util/os.c b/src/util/os.c new file mode 100644 index 000000000..6360869d0 --- /dev/null +++ b/src/util/os.c @@ -0,0 +1,17 @@ +#include "os.h" + +#if defined(WIN32) +#include +#elif defined(__GCC__) +#include +#endif + +int os_mkdir(const char * path, int mode) +{ +#ifdef WIN32 + mode = mode; + return _mkdir(path); +#else /* POSIX is our last hope */ + return mkdir(path, (mode_t)mode); +#endif +} \ No newline at end of file diff --git a/src/util/os.h b/src/util/os.h new file mode 100644 index 000000000..64e17e5e9 --- /dev/null +++ b/src/util/os.h @@ -0,0 +1,29 @@ +/* +Copyright (c) 1998-2010, Enno Rehling + Katja Zedel + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +**/ + +#ifndef _OS_H +#define _OS_H +#ifdef __cplusplus +extern "C" { +#endif + + extern int os_mkdir(const char * path, int mode); +#ifdef __cplusplus +} +#endif +#endif