| 19 | // file (as well as to stdout). This inits the global variable logfile_g. |
| 20 | |
| 21 | void OpenLogFile( // also inits the global variable logfile_g |
| 22 | const char* path) // in: log file path, default is "stasm.log" |
| 23 | { |
| 24 | if (!logfile_g) |
| 25 | { |
| 26 | if (print_g) |
| 27 | printf("Generating %s\n", path); |
| 28 | logfile_g = fopen(path, "wb"); |
| 29 | if (!logfile_g) |
| 30 | Err("Cannot open \"%s\"", path); |
| 31 | // check that we can write to the log file |
| 32 | if (fputs("log file\n", logfile_g) < 0) |
| 33 | Err("Cannot write to \"%s\"", path); |
| 34 | rewind(logfile_g); // rewind so above test msg is not in the log file |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | // Like printf but only prints if print_g flag is set. |
| 39 | // Also prints to the log file if it is open (regardless of print_g). |