There is a static library I use in my program which can only take filenames as its input, not actual file contents. There is nothing I can do about the library's source code. So I want to: create a brand-new file, store data to being processed into it, flush it onto the disk(?), pass its name to the library, then delete it.
But I also want this process to be rather secure:
1) the file must be created anew, without any bogus data (maybe it's not critical, but whatever);
2) anyone but my process must not be able read or write from/to this file (I want the library to process my actual data, not bogus data some wiseguy managed to plug in);
3) after I'm done with this file, it must be deleted (okay, if someone TerminateProcess()
me, I guess there is nothing much can be done, but still).
The library seems to use non-Unicode fopen()
to open the given file though, so I am not quite sure how to handle all this, since the program is intended to run on Windows. Any suggestions?
In general, it's safe to delete anything in the Temp folder. Sometimes, you may get a "can't delete because the file is in use" message, but you can just skip those files. For safety, do your Temp directory deleting just after you reboot the computer.
Is it safe to delete temp files? Yes, it's safe to delete temporary files from Windows. Most of the time, they'll be deleted automatically — if they're not, you can go in and delete them yourself without any worries.
There's no hard-and-fast rule about when you should delete temporary files. If you want your computer in top operating condition, then it's recommended that you delete temporary files once they're no longer being used by an app. You can delete your system's temporary files as often as you feel comfortable doing so.
There's nothing harmful about temporary files, but once the cached data they contain has served its purpose, they're no longer needed. Ideally, unneeded temp files should be deleted by the process or program that created them.
You have a lot of suggestions already, but another option that I don't think has been mentioned is using named pipes. It will depend on the library in question as to whether it works or not, but it might be worth a try. You can create a named pipe in your application using the CreateNamedPipe
function, and pass the name of the pipe to the library to operate on (the filename you would pass would be \\.\pipe\PipeName). Whether the library accepts a filename like that or not is something you would have to try, but if it works the advantage is your file never has to actually be written to disk.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With