Skip to content
Advertisement

Linux. Not printing to file

i’m just coding module for HLDS server extension metamod. I wrote a simple utility function for writing logs in format %LOGNAME%_%DATE%.log In windows that function is working fine, but in linux it create file but write nothing. First I try to search information about that, but I do not found a solution. I try to fflush file handle, set buffer to _IONBF mode, but nothing is helping. Thank you very much for reading this and helping me with that problem.

JavaScript

Advertisement

Answer

You should only check errno if and only if the previous function failed.

If the previous call didn’t fail the value of errno is undefined.

So to properly check for errors you must first check if the fopen call returned a null pointer:

JavaScript
Advertisement