update win32 port : use correct temp dir value and correct open function according to the compiler

SVN revision: 32882
This commit is contained in:
doursse 2007-11-25 16:22:58 +00:00 committed by doursse
parent 4317fe9155
commit 5b257881d7
2 changed files with 39 additions and 21 deletions

View File

@ -3,7 +3,8 @@
*/ */
#ifdef _WIN32 #ifdef _WIN32
# include <windows.h> # include <share.h>
# include <sys/stat.h>
#endif /* _WIN32 */ #endif /* _WIN32 */
@ -590,24 +591,32 @@ data_write(void)
cd = l->data; cd = l->data;
if ((cd->shared) || (cd->programs)) if ((cd->shared) || (cd->programs))
{ {
char tmpn[4096];
int fd; int fd;
#ifdef _WIN32 #ifdef _WIN32
int ret; char *tmpdir;
char path[4096];
#endif /* _WIN32 */ #endif /* _WIN32 */
char tmpn[4096];
#ifdef _WIN32 #ifdef _WIN32
ret = GetTempPath(_MAX_PATH, path); tmpdir = getenv("TMP");
if ((ret > _MAX_PATH) || (ret == 0)) if (!tmpdir) tmpdir = getenv("TEMP");
fd = -1; if (!tmpdir) tmpdir = getenv("USERPROFILE");
else if (!tmpdir) tmpdir = getenv("WINDIR");
if (tmpdir)
{ {
if (!GetTempFileName(path, "edj", 0, tmpn)) snprintf(tmpn, _MAX_PATH, "%s/edje_cc.sma-tmp-XXXXXX", tmpdir);
fd = -1; # ifdef __MINGW32__
if (_mktemp(tmpn))
fd = _sopen(tmpn, _O_RDWR | _O_BINARY | _O_CREAT, _SH_DENYNO, _S_IREAD | _S_IWRITE);
# else
if (!_mktemp_s(tmpn, _MAX_PATH))
_sopen_s(&fd, tmpn, _O_RDWR | _O_BINARY | _O_CREAT, _SH_DENYNO, _S_IREAD | _S_IWRITE);
# endif /* __MINGW32__ */
else else
fd = open(tmpn, _O_RDWR | _O_BINARY | _O_CREAT, 0444); fd = -1;
} }
else
fd= -1;
#else #else
strcpy(tmpn, "/tmp/edje_cc.sma-tmp-XXXXXX"); strcpy(tmpn, "/tmp/edje_cc.sma-tmp-XXXXXX");
fd = mkstemp(tmpn); fd = mkstemp(tmpn);
@ -693,16 +702,25 @@ data_write(void)
} }
close(fd); close(fd);
#ifdef _WIN32 #ifdef _WIN32
ret = GetTempPath(_MAX_PATH, path); tmpdir = getenv("TMP");
if ((ret > _MAX_PATH) || (ret == 0)) if (!tmpdir) tmpdir = getenv("TEMP");
fd = -1; if (!tmpdir) tmpdir = getenv("USERPROFILE");
else if (!tmpdir) tmpdir = getenv("WINDIR");
if (tmpdir)
{ {
if (!GetTempFileName(path, "edj", 0, tmpo)) snprintf(tmpo, _MAX_PATH, "%s/edje_cc.amx-tmp-XXXXXX", tmpdir);
fd = -1; # ifdef __MINGW32__
if (_mktemp(tmpo))
fd = _sopen(tmpo, _O_RDWR | _O_BINARY | _O_CREAT, _SH_DENYNO, _S_IREAD | _S_IWRITE);
# else
if (!_mktemp_s(tmpo, _MAX_PATH))
_sopen_s(&fd, tmpo, _O_RDWR | _O_BINARY | _O_CREAT, _SH_DENYNO, _S_IREAD | _S_IWRITE);
# endif /* __MINGW32__ */
else else
fd = open(tmpo, _O_RDWR | _O_BINARY | _O_CREAT, 0444); fd = -1;
} }
else
fd= -1;
#else #else
strcpy(tmpo, "/tmp/edje_cc.amx-tmp-XXXXXX"); strcpy(tmpo, "/tmp/edje_cc.amx-tmp-XXXXXX");
fd = mkstemp(tmpo); fd = mkstemp(tmpo);

View File

@ -163,10 +163,10 @@ source_fetch_file(const char *fil, const char *filname)
*slash = '\0'; *slash = '\0';
dir_len = strlen(dir); dir_len = strlen(dir);
} }
l = pp - p + dir_len + 1; l = pp - p + dir_len + 1;
file = mem_alloc(l); file = mem_alloc(l);
if (!dir_len) if (!dir_len)
snprintf(file, l - 1, "%s", p + 1); snprintf(file, l - 1, "%s", p + 1);
else else
@ -174,7 +174,7 @@ source_fetch_file(const char *fil, const char *filname)
fname = strdup(p + 1); fname = strdup(p + 1);
pp = strrchr(fname, end); pp = strrchr(fname, end);
if (pp) *pp = 0; if (pp) *pp = '\0';
forgetit = 1; forgetit = 1;
} }
} }