c++ - Check for writing permissions to file in Windows/Linux -


I would like to know how to write for a folder, how to check it.

C is writing a C ++ project and I should print some data in the result.txt file, but I have to know whether I have permission or not.

Is there a separate check between Linux and Windows? Because my project should run on Linux and currently I am working in Visual Studio.

Try checking the permissions file open and check if it is successful. If not, and set to errno (from heading to value EACCES [yes, with an S]], then you do not have enough permissions. Example for Stdio:

  FILE * fp = fopen ("results.txt", "w"); if (fp == faucet) {if (errno == EACCES) cerr & Lt; & lt; "deprived of permission" & lt; & lt; endl; else cerr & lt; "Something went wrong:"  

Iostreams will work slightly differently. AFAIK, do not guarantee to set not error on both platforms They are, or report more specific errors than "failure."

Jerry Coffin has written, Do not rely on separate access test functions because your program The race conditions and safety holes will be prone to.


Comments