Here is a snapshot of a function that I am porting to my Windows machine from here using Visual Studio.
bool MinidumpFileWriter::Open(const char *path) {
assert(file_ == -1);
#if __linux__
file_ = sys_open(path, O_WRONLY | O_CREAT | O_EXCL, 0600);
#else
file_ = open(path, O_WRONLY | O_CREAT | O_EXCL, 0600);
#endif
return file_ != -1;
}
Currently, this works fine on my Linux machine. Now when I try to port it to my Windows machine like this:
bool MinidumpFileWriter::Open(const char *path) {
assert(file_ == -1);
#if __linux__
file_ = sys_open(path, O_WRONLY | O_CREAT | O_EXCL, 0600);
return file_ != -1;
#elif _Win32
HANDLE hFile;
hFile = CreateFile(path, // file to open
GENERIC_READ, // open for reading
FILE_SHARE_READ, // share for reading
NULL, // default security
OPEN_EXISTING, // existing file only
FILE_ATTRIBUTE_NORMAL, // normal file
NULL);
if (hFile == INVALID_HANDLE_VALUE){
return false;
}
else{
return true;
}
#else
file_ = open(path, O_WRONLY | O_CREAT | O_EXCL, 0600);
return file_ != -1;
#endif
}
The open
function in the '#else' macro gives me an error that it is not recognized. From my understanding of Operating System macros, Visual Studio should not worry about what is inside the directives, and compile the Windows part of code only. But it isn't happening like that. Why is it?