- 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:
parent
80f062d8ce
commit
a4cad316e7
5 changed files with 36 additions and 73 deletions
|
@ -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,14 +2240,11 @@ int CEXEBuild::check_write_output_errors() const
|
|||
return PS_ERROR;
|
||||
}
|
||||
|
||||
{
|
||||
int ns=build_sections.getlen()/sizeof(section);
|
||||
if (!ns)
|
||||
if (!build_sections.getlen())
|
||||
{
|
||||
ERROR_MSG("Error: invalid script: no sections specified\n");
|
||||
return PS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (!build_entries.getlen())
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 <typename T>
|
||||
inline size_t __iconv_adaptor
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue