diff --git a/Source/build.cpp b/Source/build.cpp index a068e529..8f08324e 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -501,15 +501,8 @@ string get_executable_path(const char* argv0) { #endif } -string get_dirname(const string& path) { - string::size_type last_separator_pos = path.rfind(PLATFORM_PATH_SEPARATOR_C); - if (last_separator_pos == string::npos) - return path; - return path.substr(0, last_separator_pos); -} - string get_executable_dir(const char *argv0) { - return get_dirname(get_executable_path(argv0)); + return get_dir_name(get_executable_path(argv0)); } } // end anonymous namespace @@ -2247,13 +2240,10 @@ int CEXEBuild::check_write_output_errors() const return PS_ERROR; } + if (!build_sections.getlen()) { - int ns=build_sections.getlen()/sizeof(section); - if (!ns) - { - ERROR_MSG("Error: invalid script: no sections specified\n"); - return PS_ERROR; - } + ERROR_MSG("Error: invalid script: no sections specified\n"); + return PS_ERROR; } if (!build_entries.getlen()) diff --git a/Source/makenssi.cpp b/Source/makenssi.cpp index a24249dc..a90f1b51 100644 --- a/Source/makenssi.cpp +++ b/Source/makenssi.cpp @@ -329,32 +329,19 @@ int main(int argc, char **argv) } if (do_cd) { - char dirbuf[1024]=""; - char *p; -#ifdef _WIN32 - GetFullPathName(sfile,sizeof(dirbuf),dirbuf,&p); - p=CharPrev(dirbuf,p); -#else - getcwd(dirbuf,sizeof(dirbuf)-strlen(sfile)-2); - if (dirbuf[strlen(dirbuf)-1]!=PLATFORM_PATH_SEPARATOR_C) - strcat(dirbuf,PLATFORM_PATH_SEPARATOR_STR); - strcat(dirbuf,sfile); - p=strrchr(dirbuf,PLATFORM_PATH_SEPARATOR_C); -#endif - if (!p) p=dirbuf; - *p=0; - if (dirbuf[0]) + string dir = get_dir_name(get_full_path(sfile)); + if (!dir.empty()) { if (build.display_script) { - fprintf(g_output,"Changing directory to: \"%s\"\n",dirbuf); + fprintf(g_output,"Changing directory to: \"%s\"\n",dir.c_str()); fflush(g_output); } - if (chdir(dirbuf)) + if (chdir(dir.c_str())) { if (build.display_errors) { - fprintf(g_output,"Error changing directory to \"%s\"\n",dirbuf); + fprintf(g_output,"Error changing directory to \"%s\"\n",dir.c_str()); fflush(g_output); } return 1; diff --git a/Source/script.cpp b/Source/script.cpp index bb660b26..f12ac88d 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -58,8 +58,8 @@ char *CEXEBuild::set_timestamp_predefine(char *filename) definedlist.del("__TIMESTAMP__"); } - char timestampbuf[256] = ""; #ifdef _WIN32 + char timestampbuf[256] = ""; char datebuf[128] = ""; char timebuf[128] = ""; WIN32_FIND_DATA fd; @@ -83,13 +83,7 @@ char *CEXEBuild::set_timestamp_predefine(char *filename) #else struct stat st; if (!stat(filename, &st)) - { - ctime_r(&st.st_mtime, timestampbuf); - char *p = timestampbuf + strlen(timestampbuf); - while (!*p || *p == '\n') - *p-- = 0; - definedlist.add("__TIMESTAMP__",timestampbuf); - } + definedlist.add("__TIMESTAMP__",ctime(&st.st_mtime)); #endif return oldtimestamp; diff --git a/Source/util.cpp b/Source/util.cpp index 0d24e512..4306d69d 100644 --- a/Source/util.cpp +++ b/Source/util.cpp @@ -398,32 +398,6 @@ int wsprintf(char *s, const char *format, ...) { return res; } -char *my_realpath(char *path) -{ -#ifdef PATH_MAX - static char buffer[PATH_MAX]; -#else - int path_max = pathconf(path, _PC_PATH_MAX); - if (path_max <= 0) - path_max = 4096; - char *buffer = (char *) malloc(path_max); - if (!buffer) - return path; -#endif - if (!realpath(path, buffer)) - strcpy(buffer, path); - return buffer; -} - -void my_free_realpath(char *path, char *buffer) -{ -#ifndef PATH_MAX - if (buffer != path) - free(buffer); -#endif -} - - #define MY_ERROR_MSG(x) {if (g_display_errors) {fprintf(g_output,"%s", x);}} char *my_convert(const char *path) @@ -523,11 +497,30 @@ string get_full_path(const string &path) { assert(rc <= 1024); // path size is limited by MAX_PATH (260) assert(rc != 0); // rc==0 in case of error return string(real_path); -#else - // TODO: inline my_{,free_}realpath - char *real_path = my_realpath(path.c_str()); - string result(real_path); - my_free_realpath(real_path); +#else//_WIN32 +#ifdef PATH_MAX + static char buffer[PATH_MAX]; +#else//PATH_MAX + int path_max = pathconf(path, _PC_PATH_MAX); + if (path_max <= 0) + path_max = 4096; + char *buffer = (char *) malloc(path_max); + if (!buffer) + return string(path); +#endif//PATH_MAX + if (!realpath(path.c_str(), buffer)) + strcpy(buffer, path.c_str()); + string result(buffer); +#ifndef PATH_MAX + free(buffer); +#endif//!PATH_MAX return result; #endif//_WIN32 } + +string get_dir_name(const string& path) { + string::size_type last_separator_pos = path.rfind(PLATFORM_PATH_SEPARATOR_C); + if (last_separator_pos == string::npos) + return path; + return path.substr(0, last_separator_pos); +} diff --git a/Source/util.h b/Source/util.h index cbd78c77..12ca8ade 100644 --- a/Source/util.h +++ b/Source/util.h @@ -45,13 +45,12 @@ size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm); (((x)&0x000000FF) << 24) ) std::string get_full_path(const std::string &path); +std::string get_dir_name(const std::string& path); #ifndef _WIN32 char *CharPrev(const char *s, const char *p); char *CharNext(const char *s); int wsprintf(char *s, const char *format, ...); -char *my_realpath(char *path); -void my_free_realpath(char *path, char *buffer); // iconv const inconsistency workaround by Alexandre Oliva template inline size_t __iconv_adaptor