[ARCHIVER]
* BUG: Be able to create the executable file if /tmp and the target directory are not on the same device. git-svn-id: svn://localhost/gambas/trunk@5603 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
b3640ae064
commit
9f1286f161
4 changed files with 59 additions and 2 deletions
|
@ -21,4 +21,8 @@
|
|||
|
||||
***************************************************************************/
|
||||
|
||||
#include "gb_common.h"
|
||||
#include "gb_error.h"
|
||||
#include "gb_alloc.h"
|
||||
|
||||
#include "gb_file_temp.h"
|
||||
|
|
|
@ -130,8 +130,11 @@ static void make_executable(void)
|
|||
|
||||
if (rename(TEMP_EXEC, ARCH_output))
|
||||
{
|
||||
err = "Cannot create executable";
|
||||
goto __ERROR;
|
||||
if (FILE_copy(TEMP_EXEC, ARCH_output))
|
||||
{
|
||||
err = "Cannot create executable";
|
||||
goto __ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
|
@ -133,6 +133,7 @@ void FILE_chgrp(const char *path, const char *group);
|
|||
|
||||
bool FILE_exist(const char *path);
|
||||
time_t FILE_get_time(const char *path);
|
||||
bool FILE_copy(const char *src, const char *dst);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1039,6 +1039,55 @@ time_t FILE_get_time(const char *path)
|
|||
return (time_t)-1L;
|
||||
}
|
||||
|
||||
bool FILE_copy(const char *src, const char *dst)
|
||||
{
|
||||
int src_fd;
|
||||
int dst_fd;
|
||||
ssize_t len;
|
||||
char *buf = NULL;
|
||||
int save_errno;
|
||||
|
||||
src_fd = open(src, O_RDONLY);
|
||||
if (src_fd < 0)
|
||||
return TRUE;
|
||||
|
||||
dst_fd = open(dst, O_WRONLY);
|
||||
if (dst_fd < 0)
|
||||
{
|
||||
save_errno = errno;
|
||||
close(src_fd);
|
||||
errno = save_errno;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ALLOC(&buf, MAX_IO);
|
||||
|
||||
for(;;)
|
||||
{
|
||||
len = read(src_fd, buf, MAX_IO);
|
||||
if (len == 0)
|
||||
break;
|
||||
if (len < 0 && errno == EINTR)
|
||||
continue;
|
||||
if (write(dst_fd, buf, len) < 0)
|
||||
{
|
||||
save_errno = errno;
|
||||
close(src_fd);
|
||||
close(dst_fd);
|
||||
unlink(dst);
|
||||
errno = save_errno;
|
||||
IFREE(buf);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
close(src_fd);
|
||||
close(dst_fd);
|
||||
IFREE(buf);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
const char *FILE_getcwd(const char *subdir)
|
||||
|
|
Loading…
Reference in a new issue