Reputation: 3391
I'm working on a project that encrypts data at rest, then the encrypted data is decrypted into a temporary file in order to write the unencrypted data to an XML stream. The encryption and decryption work, but I am having trouble reading the data from the file. I believe this is due to the file still being open, but I can't close the file since it gets deleted on close. I'm wondering if there's a way to read from this file?
As a last resort I could rewrite the code to just use a large encrypted buffer instead of a file, but I'd like to figure out how to read the data from the open file.
EDIT: I should've said earlier that I have the decryption logic in a C++ class and that I port the functions I need to C with extern "C". The function doing the decryption is in C++, which allowed me to get a HANDLE from the file descriptor and then use FlushFileBuffers(HANDLE) to flush the buffer.
Upvotes: 0
Views: 108
Reputation: 11963
Input and output can be buffered both at the C library level and at the kernel level; writes from one process are not necessarily immediately visible to another process until the buffer has been flushed. If you're using the C library's standard IO features, you can use fflush
in the writer process to make sure its output is available to the reader process.
Upvotes: 1