From: Martin Ling Date: Wed, 20 Nov 2013 15:54:10 +0000 (+0000) Subject: Use a more logical set of SP_MODE_* flags. X-Git-Tag: libserialport-0.1.0~87 X-Git-Url: https://sigrok.org/gitweb/?a=commitdiff_plain;h=a036341bdf97dda25f715056a1c5a6a8b8be73af;hp=20e63a77b58073e2dacdd85857a4f78b807a055c;p=libserialport.git Use a more logical set of SP_MODE_* flags. --- diff --git a/libserialport.h.in b/libserialport.h.in index 264c7db..fa5ba1a 100644 --- a/libserialport.h.in +++ b/libserialport.h.in @@ -101,10 +101,10 @@ enum sp_return { /** Port access modes. */ enum sp_mode { - /** Open port for read/write access. */ - SP_MODE_RDWR = 1, - /** Open port for read access only. */ - SP_MODE_RDONLY = 2, + /** Open port for read access. */ + SP_MODE_READ = 1, + /** Open port for write access. */ + SP_MODE_WRITE = 2, /** Open port in non-blocking mode. */ SP_MODE_NONBLOCK = 4, }; diff --git a/serialport.c b/serialport.c index 7127cb3..353cd34 100644 --- a/serialport.c +++ b/serialport.c @@ -422,9 +422,10 @@ enum sp_return sp_open(struct sp_port *port, enum sp_mode flags) sprintf(escaped_port_name, "\\\\.\\%s", port->name); /* Map 'flags' to the OS-specific settings. */ - desired_access |= GENERIC_READ; flags_and_attributes = FILE_ATTRIBUTE_NORMAL; - if (flags & SP_MODE_RDWR) + if (flags & SP_MODE_READ) + desired_access |= GENERIC_READ; + if (flags & SP_MODE_WRITE) desired_access |= GENERIC_WRITE; if (flags & SP_MODE_NONBLOCK) flags_and_attributes |= FILE_FLAG_OVERLAPPED; @@ -443,10 +444,12 @@ enum sp_return sp_open(struct sp_port *port, enum sp_mode flags) int ret; /* Map 'flags' to the OS-specific settings. */ - if (flags & SP_MODE_RDWR) + if (flags & (SP_MODE_READ | SP_MODE_WRITE)) flags_local |= O_RDWR; - if (flags & SP_MODE_RDONLY) + else if (flags & SP_MODE_READ) flags_local |= O_RDONLY; + else if (flags & SP_MODE_WRITE) + flags_local |= O_WRONLY; if (flags & SP_MODE_NONBLOCK) flags_local |= O_NONBLOCK;