From: Uwe Hermann Date: Wed, 29 Jul 2015 17:31:43 +0000 (+0200) Subject: Various errno/strerror() related fixes. X-Git-Tag: libsigrok-0.4.0~453 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=8d5228015d0f07ce6626aa52ffb80bc4129f7dbe;p=libsigrok.git Various errno/strerror() related fixes. - Don't #include in files that don't actually need it. - Don't use strerror() on error codes from functions that don't set errno. Replace strerror() with sr_strerror() for libsigrok functions. --- diff --git a/src/hardware/agilent-dmm/api.c b/src/hardware/agilent-dmm/api.c index 82374076..cefea4f2 100644 --- a/src/hardware/agilent-dmm/api.c +++ b/src/hardware/agilent-dmm/api.c @@ -22,7 +22,6 @@ #include #include #include -#include #include "libsigrok.h" #include "libsigrok-internal.h" #include "agilent-dmm.h" diff --git a/src/hardware/agilent-dmm/sched.c b/src/hardware/agilent-dmm/sched.c index d1b76566..1fe962f5 100644 --- a/src/hardware/agilent-dmm/sched.c +++ b/src/hardware/agilent-dmm/sched.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include "libsigrok.h" #include "libsigrok-internal.h" diff --git a/src/hardware/atten-pps3xxx/api.c b/src/hardware/atten-pps3xxx/api.c index 10dfa2ad..fa367cc2 100644 --- a/src/hardware/atten-pps3xxx/api.c +++ b/src/hardware/atten-pps3xxx/api.c @@ -18,7 +18,6 @@ */ #include -#include #include "protocol.h" /* @@ -142,7 +141,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options, int modelid) memset(packet, 0, PACKET_SIZE); if ((ret = serial_read_nonblocking(serial, packet, PACKET_SIZE)) < 0) { sr_err("Unable to read while probing for hardware: %s", - strerror(errno)); + sr_strerror(ret)); return NULL; } if (ret != PACKET_SIZE || packet[0] != 0xaa || packet[1] != 0xaa) { diff --git a/src/hardware/atten-pps3xxx/protocol.c b/src/hardware/atten-pps3xxx/protocol.c index 297fe831..8e678a16 100644 --- a/src/hardware/atten-pps3xxx/protocol.c +++ b/src/hardware/atten-pps3xxx/protocol.c @@ -18,7 +18,6 @@ */ #include -#include #include "protocol.h" static void dump_packet(char *msg, uint8_t *packet) diff --git a/src/hardware/beaglelogic/protocol.c b/src/hardware/beaglelogic/protocol.c index a07bb203..e1f6009f 100644 --- a/src/hardware/beaglelogic/protocol.c +++ b/src/hardware/beaglelogic/protocol.c @@ -17,7 +17,6 @@ * along with this program. If not, see . */ -#include #include #include #include diff --git a/src/hardware/colead-slm/api.c b/src/hardware/colead-slm/api.c index 38c54580..fe697277 100644 --- a/src/hardware/colead-slm/api.c +++ b/src/hardware/colead-slm/api.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include "libsigrok.h" #include "libsigrok-internal.h" diff --git a/src/hardware/colead-slm/protocol.c b/src/hardware/colead-slm/protocol.c index 01e748fb..9a7c9fd0 100644 --- a/src/hardware/colead-slm/protocol.c +++ b/src/hardware/colead-slm/protocol.c @@ -19,7 +19,6 @@ #include #include -#include #include #include "libsigrok.h" #include "libsigrok-internal.h" diff --git a/src/hardware/conrad-digi-35-cpu/protocol.h b/src/hardware/conrad-digi-35-cpu/protocol.h index fcde852e..1c3885a4 100644 --- a/src/hardware/conrad-digi-35-cpu/protocol.h +++ b/src/hardware/conrad-digi-35-cpu/protocol.h @@ -27,7 +27,6 @@ #define LIBSIGROK_HARDWARE_CONRAD_DIGI_35_CPU_PROTOCOL_H #include -#include #include #include #include "libsigrok.h" diff --git a/src/hardware/fluke-dmm/api.c b/src/hardware/fluke-dmm/api.c index 1b4ce404..9c6c8a94 100644 --- a/src/hardware/fluke-dmm/api.c +++ b/src/hardware/fluke-dmm/api.c @@ -22,7 +22,6 @@ #include #include #include -#include #include "libsigrok.h" #include "libsigrok-internal.h" #include "fluke-dmm.h" diff --git a/src/hardware/fluke-dmm/fluke.c b/src/hardware/fluke-dmm/fluke.c index e708518d..159a4f9f 100644 --- a/src/hardware/fluke-dmm/fluke.c +++ b/src/hardware/fluke-dmm/fluke.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include "libsigrok.h" #include "libsigrok-internal.h" diff --git a/src/hardware/motech-lps-30x/api.c b/src/hardware/motech-lps-30x/api.c index b9fee49d..ba647837 100644 --- a/src/hardware/motech-lps-30x/api.c +++ b/src/hardware/motech-lps-30x/api.c @@ -24,7 +24,6 @@ */ #include -#include #include #include #include "protocol.h" @@ -285,15 +284,16 @@ SR_PRIV int lps_process_status(struct sr_dev_inst* sdi, int stat) SR_PRIV int lps_query_status(struct sr_dev_inst* sdi) { char buf[LINELEN_MAX]; - int stat; + int stat, ret; struct dev_context* devc; devc = (struct dev_context*)sdi->priv; devc->req_sent_at = g_get_real_time(); - if (lps_cmd_reply(buf, sdi->conn, "STATUS") < 0) { - sr_err("%s: Failed to read status: %d %s", __func__, errno, strerror(errno)); + if ((ret = lps_cmd_reply(buf, sdi->conn, "STATUS")) < 0) { + sr_err("%s: Failed to read status: %s.", __func__, + sr_strerror(ret)); return SR_ERR; } @@ -379,7 +379,7 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o struct sr_channel_group *cg; GSList *devices; const char *conn, *serialcomm; - int cnt; + int cnt, ret; gchar buf[LINELEN_MAX]; gchar channel[10]; char *verstr; @@ -434,7 +434,7 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o /* Query version */ verstr = NULL; - if (lps_cmd_reply(buf, serial, "VERSION") == SR_OK) { + if ((ret = lps_cmd_reply(buf, serial, "VERSION")) == SR_OK) { if (strncmp(buf, "Ver-", 4)) { sr_spew("Version string %s not recognized.", buf); goto exit_err; @@ -445,7 +445,8 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o } else /* Bug in device FW 1.17: Querying version string fails while output is active. Therefore just print an error message, but do not exit with error. */ - sr_err("Failed to query for hardware version: %d %s", errno, strerror(errno)); + sr_err("Failed to query for hardware version: %s.", + sr_strerror(ret)); sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->status = SR_ST_INACTIVE; diff --git a/src/hardware/norma-dmm/protocol.h b/src/hardware/norma-dmm/protocol.h index 951734e8..80927150 100644 --- a/src/hardware/norma-dmm/protocol.h +++ b/src/hardware/norma-dmm/protocol.h @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include "libsigrok.h" diff --git a/src/hardware/serial-dmm/api.c b/src/hardware/serial-dmm/api.c index 5a89b3d1..c71dd075 100644 --- a/src/hardware/serial-dmm/api.c +++ b/src/hardware/serial-dmm/api.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include "libsigrok.h" #include "libsigrok-internal.h" diff --git a/src/hardware/serial-dmm/protocol.c b/src/hardware/serial-dmm/protocol.c index 99a71694..84b12cf0 100644 --- a/src/hardware/serial-dmm/protocol.c +++ b/src/hardware/serial-dmm/protocol.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include "libsigrok.h" #include "libsigrok-internal.h"