1
0
mirror of https://github.com/wjwwood/serial.git synced 2026-01-22 19:54:57 +08:00

Fix compiler warnings on Windows

This commit is contained in:
William Woodall 2013-08-02 21:20:16 -07:00
parent 3292f2b682
commit e11abb04f2
4 changed files with 25 additions and 21 deletions

View File

@ -55,7 +55,11 @@ int run(int argc, char **argv)
// Argument 2 is the baudrate // Argument 2 is the baudrate
unsigned long baud = 0; unsigned long baud = 0;
#ifdef WIN32
sscanf_s(argv[2], "%lu", &baud);
#else
sscanf(argv[2], "%lu", &baud); sscanf(argv[2], "%lu", &baud);
#endif
// port, baudrate, timeout in milliseconds // port, baudrate, timeout in milliseconds
serial::Serial my_serial(port, baud, serial::Timeout::simpleTimeout(1000)); serial::Serial my_serial(port, baud, serial::Timeout::simpleTimeout(1000));

View File

@ -599,8 +599,7 @@ public:
private: private:
// Disable copy constructors // Disable copy constructors
Serial(const Serial&); Serial(const Serial&);
void operator=(const Serial&); Serial& operator=(const Serial&);
const Serial& operator=(Serial);
std::string read_cache_; //!< Cache for doing reads in chunks. std::string read_cache_; //!< Cache for doing reads in chunks.
@ -624,8 +623,7 @@ private:
class SerialException : public std::exception class SerialException : public std::exception
{ {
// Disable copy constructors // Disable copy constructors
void operator=(const SerialException&); SerialException& operator=(const SerialException&);
const SerialException& operator=(SerialException);
std::string e_what_; std::string e_what_;
public: public:
SerialException (const char *description) { SerialException (const char *description) {
@ -645,8 +643,7 @@ public:
class IOException : public std::exception class IOException : public std::exception
{ {
// Disable copy constructors // Disable copy constructors
void operator=(const IOException&); IOException& operator=(const IOException&);
const IOException& operator=(IOException);
std::string file_; std::string file_;
int line_; int line_;
std::string e_what_; std::string e_what_;
@ -655,7 +652,13 @@ public:
explicit IOException (std::string file, int line, int errnum) explicit IOException (std::string file, int line, int errnum)
: file_(file), line_(line), errno_(errnum) { : file_(file), line_(line), errno_(errnum) {
std::stringstream ss; std::stringstream ss;
ss << "IO Exception (" << errno_ << "): " << strerror (errnum); char error_str [1024];
#ifdef WIN32
strerror_s(error_str, 1024, errnum);
#else
error_str = strerror(errnum);
#endif
ss << "IO Exception (" << errno_ << "): " << error_str;
ss << ", file " << file_ << ", line " << line_ << "."; ss << ", file " << file_ << ", line " << line_ << ".";
e_what_ = ss.str(); e_what_ = ss.str();
} }
@ -681,7 +684,6 @@ public:
class PortNotOpenedException : public std::exception class PortNotOpenedException : public std::exception
{ {
// Disable copy constructors // Disable copy constructors
void operator=(const PortNotOpenedException&);
const PortNotOpenedException& operator=(PortNotOpenedException); const PortNotOpenedException& operator=(PortNotOpenedException);
std::string e_what_; std::string e_what_;
public: public:

View File

@ -49,7 +49,7 @@ Serial::SerialImpl::open ()
} }
LPCWSTR lp_port = port_.c_str(); LPCWSTR lp_port = port_.c_str();
fd_ = CreateFile(lp_port, fd_ = CreateFileW(lp_port,
GENERIC_READ | GENERIC_WRITE, GENERIC_READ | GENERIC_WRITE,
0, 0,
0, 0,
@ -508,7 +508,7 @@ Serial::SerialImpl::getCTS ()
THROW (IOException, "Error getting the status of the CTS line."); THROW (IOException, "Error getting the status of the CTS line.");
} }
return (bool) (MS_CTS_ON & dwModemStatus); return (MS_CTS_ON & dwModemStatus) != 0;
} }
bool bool
@ -522,7 +522,7 @@ Serial::SerialImpl::getDSR ()
THROW (IOException, "Error getting the status of the DSR line."); THROW (IOException, "Error getting the status of the DSR line.");
} }
return (bool) (MS_DSR_ON & dwModemStatus); return (MS_DSR_ON & dwModemStatus) != 0;
} }
bool bool
@ -536,7 +536,7 @@ Serial::SerialImpl::getRI()
THROW (IOException, "Error getting the status of the RI line."); THROW (IOException, "Error getting the status of the RI line.");
} }
return (bool) (MS_RING_ON & dwModemStatus); return (MS_RING_ON & dwModemStatus) != 0;
} }
bool bool
@ -551,7 +551,7 @@ Serial::SerialImpl::getCD()
THROW (IOException, "Error getting the status of the CD line."); THROW (IOException, "Error getting the status of the CD line.");
} }
return (bool) (MS_RLSD_ON & dwModemStatus); return (MS_RLSD_ON & dwModemStatus) != 0;
} }
void void

View File

@ -37,7 +37,6 @@ public:
private: private:
// Disable copy constructors // Disable copy constructors
ScopedReadLock(const ScopedReadLock&); ScopedReadLock(const ScopedReadLock&);
void operator=(const ScopedReadLock&);
const ScopedReadLock& operator=(ScopedReadLock); const ScopedReadLock& operator=(ScopedReadLock);
SerialImpl *pimpl_; SerialImpl *pimpl_;
@ -54,7 +53,6 @@ public:
private: private:
// Disable copy constructors // Disable copy constructors
ScopedWriteLock(const ScopedWriteLock&); ScopedWriteLock(const ScopedWriteLock&);
void operator=(const ScopedWriteLock&);
const ScopedWriteLock& operator=(ScopedWriteLock); const ScopedWriteLock& operator=(ScopedWriteLock);
SerialImpl *pimpl_; SerialImpl *pimpl_;
}; };