mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-03 02:41:08 +00:00
Fix r_file_truncate
This commit is contained in:
parent
0ea452d0f5
commit
06ec145106
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user