diff --git a/src/irda.c b/src/irda.c index fba618c..b9ee35e 100644 --- a/src/irda.c +++ b/src/irda.c @@ -114,7 +114,7 @@ const char* irda_errmsg (void) int irda_init (void) { #ifdef _WIN32 - WSADATA wsaData = {0}; + WSADATA wsaData; WORD wVersionRequested = MAKEWORD (2, 2); if (WSAStartup (wVersionRequested, &wsaData) != 0) { TRACE ("WSAStartup"); @@ -313,7 +313,7 @@ irda_socket_connect_name (irda *device, unsigned int address, const char *name) return -1; #ifdef _WIN32 - SOCKADDR_IRDA peer = {0}; + SOCKADDR_IRDA peer; peer.irdaAddressFamily = AF_IRDA; peer.irdaDeviceID[0] = (address >> 24) & 0xFF; peer.irdaDeviceID[1] = (address >> 16) & 0xFF; @@ -324,7 +324,7 @@ irda_socket_connect_name (irda *device, unsigned int address, const char *name) else memset (peer.irdaServiceName, 0x00, 25); #else - struct sockaddr_irda peer = {0}; + struct sockaddr_irda peer; peer.sir_family = AF_IRDA; peer.sir_addr = address; if (name) @@ -348,7 +348,7 @@ irda_socket_connect_lsap (irda *device, unsigned int address, unsigned int lsap) return -1; #ifdef _WIN32 - SOCKADDR_IRDA peer = {0}; + SOCKADDR_IRDA peer; peer.irdaAddressFamily = AF_IRDA; peer.irdaDeviceID[0] = (address >> 24) & 0xFF; peer.irdaDeviceID[1] = (address >> 16) & 0xFF; @@ -356,7 +356,7 @@ irda_socket_connect_lsap (irda *device, unsigned int address, unsigned int lsap) peer.irdaDeviceID[3] = (address ) & 0xFF; snprintf (peer.irdaServiceName, 25, "LSAP-SEL%u", lsap); #else - struct sockaddr_irda peer = {0}; + struct sockaddr_irda peer; peer.sir_family = AF_IRDA; peer.sir_addr = address; peer.sir_lsap_sel = lsap; @@ -400,7 +400,7 @@ irda_socket_read (irda* device, void* data, unsigned int size) if (device == NULL) return -1; // EINVAL (Invalid argument) - struct timeval tv = {0}; + struct timeval tv; if (device->timeout >= 0) { tv.tv_sec = (device->timeout / 1000); tv.tv_usec = (device->timeout % 1000) * 1000; diff --git a/src/serial_posix.c b/src/serial_posix.c index 31ee758..8a9fef1 100644 --- a/src/serial_posix.c +++ b/src/serial_posix.c @@ -160,7 +160,7 @@ serial_configure (serial *device, int baudrate, int databits, int parity, int st return -1; // EINVAL (Invalid argument) // Retrieve the current settings. - struct termios tty = {0}; + struct termios tty; if (tcgetattr (device->fd, &tty) != 0) { TRACE ("tcgetattr"); return -1; @@ -310,7 +310,7 @@ serial_configure (serial *device, int baudrate, int databits, int parity, int st // it may be necessary to follow this call with a further call to // tcgetattr() to check that all changes have been performed successfully. - struct termios active = {0}; + struct termios active; if (tcgetattr (device->fd, &active) != 0) { TRACE ("tcgetattr"); return -1; @@ -365,14 +365,14 @@ serial_poll_internal (int fd, int queue, long timeout, const struct timeval *tim // Calculate the initial timeout, and obtain // a timestamp for updating the timeout. - struct timeval tvt = {0}, tve = {0}; + struct timeval tvt, tve; if (timeout > 0) { // Calculate the initial timeout. tvt.tv_sec = (timeout / 1000); tvt.tv_usec = (timeout % 1000) * 1000; // Calculate the timestamp. if (timestamp == NULL) { - struct timeval now = {0}; + struct timeval now; if (gettimeofday (&now, NULL) != 0) { TRACE ("gettimeofday"); return -1; @@ -381,6 +381,8 @@ serial_poll_internal (int fd, int queue, long timeout, const struct timeval *tim } else { timeradd (timestamp, &tvt, &tve); } + } else if (timeout == 0) { + timerclear (&tvt); } // Wait until the file descriptor is ready for reading/writing, or @@ -410,7 +412,7 @@ serial_poll_internal (int fd, int queue, long timeout, const struct timeval *tim // Calculate the remaining timeout. if (timeout > 0) { - struct timeval now = {0}; + struct timeval now; if (gettimeofday (&now, NULL) != 0) { TRACE ("gettimeofday"); return -1; @@ -436,7 +438,7 @@ serial_read (serial* device, void* data, unsigned int size) long timeout = device->timeout; - struct timeval timestamp = {0}; + struct timeval timestamp; if (timeout > 0) { if (gettimeofday (×tamp, NULL) != 0) { TRACE ("gettimeofday"); @@ -462,7 +464,7 @@ serial_read (serial* device, void* data, unsigned int size) } // Wait until the file descriptor is ready for reading, or the timeout expires. - int rc = serial_poll_internal (device->fd, SERIAL_QUEUE_INPUT, timeout, ×tamp); + int rc = serial_poll_internal (device->fd, SERIAL_QUEUE_INPUT, timeout, timeout > 0 ? ×tamp : NULL); if (rc < 0) { return -1; // Error during select/poll call. } else if (rc == 0) @@ -470,7 +472,7 @@ serial_read (serial* device, void* data, unsigned int size) // Calculate the remaining timeout. if (timeout > 0) { - struct timeval now = {0}, delta = {0}; + struct timeval now, delta; if (gettimeofday (&now, NULL) != 0) { TRACE ("gettimeofday"); return -1; @@ -671,7 +673,7 @@ serial_get_transmitted (serial *device) int serial_sleep (unsigned long timeout) { - struct timespec ts = {0}; + struct timespec ts; ts.tv_sec = (timeout / 1000); ts.tv_nsec = (timeout % 1000) * 1000000; @@ -689,7 +691,7 @@ serial_sleep (unsigned long timeout) int serial_timer (void) { - struct timeval tv = {0}; + struct timeval tv; if (gettimeofday (&tv, NULL) != 0) { TRACE ("gettimeofday"); return 0; diff --git a/src/serial_win32.c b/src/serial_win32.c index fcf6d6b..6945870 100644 --- a/src/serial_win32.c +++ b/src/serial_win32.c @@ -171,7 +171,7 @@ serial_configure (serial *device, int baudrate, int databits, int parity, int st return -1; // ERROR_INVALID_PARAMETER (The parameter is incorrect) // Retrieve the current settings. - DCB dcb = {0}; + DCB dcb; if (!GetCommState (device->hFile, &dcb)) { TRACE ("GetCommState"); return -1; @@ -285,7 +285,7 @@ serial_set_timeout (serial* device, long timeout) return -1; // ERROR_INVALID_PARAMETER (The parameter is incorrect) // Retrieve the current timeouts. - COMMTIMEOUTS timeouts = {0}; + COMMTIMEOUTS timeouts; if (!GetCommTimeouts (device->hFile, &timeouts)) { TRACE ("GetCommTimeouts"); return -1; @@ -501,7 +501,7 @@ serial_get_received (serial* device) if (device == NULL) return -1; // ERROR_INVALID_PARAMETER (The parameter is incorrect) - COMSTAT stats = {0}; + COMSTAT stats; if (!ClearCommError (device->hFile, NULL, &stats)) { TRACE ("ClearCommError"); @@ -518,7 +518,7 @@ serial_get_transmitted (serial* device) if (device == NULL) return -1; // ERROR_INVALID_PARAMETER (The parameter is incorrect) - COMSTAT stats = {0}; + COMSTAT stats; if (!ClearCommError (device->hFile, NULL, &stats)) { TRACE ("ClearCommError"); diff --git a/src/utils.c b/src/utils.c index db11535..952bd8a 100644 --- a/src/utils.c +++ b/src/utils.c @@ -48,7 +48,7 @@ int message (const char* fmt, ...) unsigned long sec = timestamp / 1000L, msec = timestamp % 1000L; fprintf (g_logfile, "[%li.%03li] ", sec, msec); #else - struct timeval now = {0}, timestamp = {0}; + struct timeval now, timestamp; gettimeofday (&now, NULL); timersub (&now, &g_timestamp, ×tamp); fprintf (g_logfile, "[%lli.%06lli] ", (long long)timestamp.tv_sec, (long long)timestamp.tv_usec);