open.mp
open.mp copied to clipboard
`ftouch` clobbers files
trafficstars
Describe the bug
The touch utility is meant to merely update a file's modified time, or create it if it doesn't exist, with no changes to the contents. ftouch should do the same, but seems to clobber the file contents. Really a pawn-lang bug.
To Reproduce
new File:f = fopen("moo.txt", io_write);
fwrite(f, "hi");
fclose(f);
ftouch("moo.txt");
Expected behavior
File contents should remain.
I looked at the source:
https://github.com/openmultiplayer/compiler/blob/44ad6414c748466b8b37fdf1e1170959b98bb85b/source/amx/amxfile.c#L897
f=_tfopen(fullname,__T("wb"));
if (f!=NULL) {
return fclose(f) == 0;
}
'wb' overwrites the file contents.
Wouldn't the correct thing here be having ftouch only modify the file's time instead of rewriting it?