- converted ctime_r to ctime for better portability

- more refactoring


git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3691 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2004-10-01 19:52:56 +00:00
parent 80f062d8ce
commit a4cad316e7
5 changed files with 36 additions and 73 deletions

View file

@ -501,15 +501,8 @@ string get_executable_path(const char* argv0) {
#endif #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) { 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 } // end anonymous namespace
@ -2247,13 +2240,10 @@ int CEXEBuild::check_write_output_errors() const
return PS_ERROR; return PS_ERROR;
} }
if (!build_sections.getlen())
{ {
int ns=build_sections.getlen()/sizeof(section); ERROR_MSG("Error: invalid script: no sections specified\n");
if (!ns) return PS_ERROR;
{
ERROR_MSG("Error: invalid script: no sections specified\n");
return PS_ERROR;
}
} }
if (!build_entries.getlen()) if (!build_entries.getlen())

View file

@ -329,32 +329,19 @@ int main(int argc, char **argv)
} }
if (do_cd) if (do_cd)
{ {
char dirbuf[1024]=""; string dir = get_dir_name(get_full_path(sfile));
char *p; if (!dir.empty())
#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])
{ {
if (build.display_script) 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); fflush(g_output);
} }
if (chdir(dirbuf)) if (chdir(dir.c_str()))
{ {
if (build.display_errors) 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); fflush(g_output);
} }
return 1; return 1;

View file

@ -58,8 +58,8 @@ char *CEXEBuild::set_timestamp_predefine(char *filename)
definedlist.del("__TIMESTAMP__"); definedlist.del("__TIMESTAMP__");
} }
char timestampbuf[256] = "";
#ifdef _WIN32 #ifdef _WIN32
char timestampbuf[256] = "";
char datebuf[128] = ""; char datebuf[128] = "";
char timebuf[128] = ""; char timebuf[128] = "";
WIN32_FIND_DATA fd; WIN32_FIND_DATA fd;
@ -83,13 +83,7 @@ char *CEXEBuild::set_timestamp_predefine(char *filename)
#else #else
struct stat st; struct stat st;
if (!stat(filename, &st)) if (!stat(filename, &st))
{ definedlist.add("__TIMESTAMP__",ctime(&st.st_mtime));
ctime_r(&st.st_mtime, timestampbuf);
char *p = timestampbuf + strlen(timestampbuf);
while (!*p || *p == '\n')
*p-- = 0;
definedlist.add("__TIMESTAMP__",timestampbuf);
}
#endif #endif
return oldtimestamp; return oldtimestamp;

View file

@ -398,32 +398,6 @@ int wsprintf(char *s, const char *format, ...) {
return res; 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);}} #define MY_ERROR_MSG(x) {if (g_display_errors) {fprintf(g_output,"%s", x);}}
char *my_convert(const char *path) 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 <= 1024); // path size is limited by MAX_PATH (260)
assert(rc != 0); // rc==0 in case of error assert(rc != 0); // rc==0 in case of error
return string(real_path); return string(real_path);
#else #else//_WIN32
// TODO: inline my_{,free_}realpath #ifdef PATH_MAX
char *real_path = my_realpath(path.c_str()); static char buffer[PATH_MAX];
string result(real_path); #else//PATH_MAX
my_free_realpath(real_path); 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; return result;
#endif//_WIN32 #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);
}

View file

@ -45,13 +45,12 @@ size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm);
(((x)&0x000000FF) << 24) ) (((x)&0x000000FF) << 24) )
std::string get_full_path(const std::string &path); std::string get_full_path(const std::string &path);
std::string get_dir_name(const std::string& path);
#ifndef _WIN32 #ifndef _WIN32
char *CharPrev(const char *s, const char *p); char *CharPrev(const char *s, const char *p);
char *CharNext(const char *s); char *CharNext(const char *s);
int wsprintf(char *s, const char *format, ...); 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 // iconv const inconsistency workaround by Alexandre Oliva
template <typename T> template <typename T>
inline size_t __iconv_adaptor inline size_t __iconv_adaptor