- hdl = CreateFile(serial->port, GENERIC_READ | GENERIC_WRITE, 0, 0,
- OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
+ /* Map 'flags' to the OS-specific settings. */
+ desired_access |= GENERIC_READ;
+ flags_and_attributes = FILE_ATTRIBUTE_NORMAL;
+ if (flags & SERIAL_RDWR)
+ desired_access |= GENERIC_WRITE;
+ if (flags & SERIAL_NONBLOCK)
+ flags_and_attributes |= FILE_FLAG_OVERLAPPED;
+
+ hdl = CreateFile(serial->port, desired_access, 0, 0,
+ OPEN_EXISTING, flags_and_attributes, 0);