Fix r_file_truncate

This commit is contained in:
pancake 2014-06-06 01:10:43 +02:00
parent 0ea452d0f5
commit 06ec145106

View File

@ -25,25 +25,14 @@ R_API boolt r_file_truncate (const char *filename, ut64 newsize) {
int fd;
if (r_file_is_directory (filename))
return R_FALSE;
if (r_file_exists (filename) && !r_file_is_regular (filename))
if (!r_file_exists (filename) || !r_file_is_regular (filename))
return R_FALSE;
else if (!r_file_exists (filename)){
FILE *ffd = r_sandbox_fopen (filename, "wb");
if (ffd == NULL) {
eprintf ("Cannot open '%s' for writing\n", filename);
return R_FALSE;
}
fclose (ffd);
}
#if __WINDOWS__
fd = r_sandbox_open (filename, O_RDWR, 0644);
#else
fd = r_sandbox_open (filename, O_RDWR|O_SYNC, 0644);
#endif
if (!fd || fd == -1) return R_FALSE;
if (fd < 1) return R_FALSE;
ftruncate (fd, newsize);
close (fd);
return R_TRUE;