summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominic Radermacher <blip@mockmoon-cybernetics.ch>2018-04-26 12:20:09 +0200
committerDominic Radermacher <blip@mockmoon-cybernetics.ch>2018-04-26 12:20:09 +0200
commitef2354f133f8fcf8bc445e454e031296f4f350de (patch)
tree31b41c452f1caadb3008a19c6535739069d422c4
parent4b500c16b4dce90207c914d279e5c9127d5435ba (diff)
type conversion fixes, use GIT_VERSION as VERSION informationHEADv1.3master
-rw-r--r--Makefile6
-rw-r--r--include/config.h2
-rw-r--r--src/mpd-i2c-ctrl.c13
-rw-r--r--src/socket.c5
4 files changed, 16 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index e3797dd..3f0a101 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,4 @@
+# update 2018-04-26: define VERSION as GIT_VERSION
# Update 2011-10-21: object file(s) must come before LDFLAGS and -llibs ?!
# gcc version used is 4.6.1
# I think it's time to move to autotools :-(
@@ -7,11 +8,14 @@ ECHO = /bin/echo -e
SHELL = /bin/sh
RM = /bin/rm -f
+GIT_VERSION := $(shell git --no-pager describe --tags --dirty |sed 's/\([^-]*-g\)/r\1/;s/-/./g')
+
CC = gcc
STRIP = strip
-CFLAGS = -g -Os -I./include -I/usr/include/libxml2
+CFLAGS = -g -O2 -fPIC -I./include -I/usr/include/libxml2
CFLAGS += -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wextra
CFLAGS += -Wunused -Wconversion
+CFLAGS += -DVERSION=\"$(GIT_VERSION)\"
PROGS = mpd-i2c-ctrl
diff --git a/include/config.h b/include/config.h
index 296884e..e75f317 100644
--- a/include/config.h
+++ b/include/config.h
@@ -1,4 +1,2 @@
#define CONFIG_FILE "/srv/mpd/button.conf"
-
-#define VERSION "1.2"
diff --git a/src/mpd-i2c-ctrl.c b/src/mpd-i2c-ctrl.c
index dd7dcea..6ac690b 100644
--- a/src/mpd-i2c-ctrl.c
+++ b/src/mpd-i2c-ctrl.c
@@ -1,6 +1,7 @@
+
#include <stdio.h>
#include <stdint.h>
-#include <string.h> /* strchr() */
+#include <string.h> /* strchr(), strdup() */
#include <unistd.h> /* close() */
#include <stropts.h> /* ioctl() */
#include <sys/types.h> /* AF_INET, SOCK_STREAM */
@@ -16,8 +17,6 @@
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
-/* gcc libxml-example.c -I/usr/include/libxml2 -lxml2 */
-
#include "config.h"
#include "socket.h"
@@ -82,7 +81,10 @@ void buttonlist_set(int key, const char *action)
ssize_t i2c_wr(int fd, const uint8_t *data, size_t len)
{
- if (write(fd, data, len) != len) {
+ if (len >= SSIZE_MAX) {
+ return -1;
+ }
+ if (write(fd, data, len) != (ssize_t)len) {
return -1;
}
return 0;
@@ -263,7 +265,7 @@ static int parse_config(const char *file)
long int val=strtol((char *)key, &err, 16);
if ((!*err) && (val >= 0) && (val < 256)) {
action = xmlGetProp(cur, (const xmlChar *)"action");
- buttonlist_set(val, (char *)action);
+ buttonlist_set((int)val, (char *)action);
xmlFree(action);
}
xmlFree(key);
@@ -284,6 +286,7 @@ int main(int argc, char **argv)
const char *_basename=basename(argv[0]);
if (strcmp(_basename, "mpd-send-cmd") == 0) {
if (argc != 2) {
+ printf("mpd-i2c-ctrl %s\tprogrammed by Dominic Radermacher\n", VERSION);
printf("usage: %s <command>\n", argv[0]);
return 1;
}
diff --git a/src/socket.c b/src/socket.c
index 82fee8c..40f9896 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -88,11 +88,12 @@ ssize_t sock_readln(int sd, char *buf, size_t len)
if ((newline = memchr(bp, '\n', (size_t)n)) != NULL) {
n = newline - bp + 1;
}
- if ((n = read(sd, bp, n)) == -1) {
+ if ((n = read(sd, bp, (size_t)n)) == -1) {
return -1;
}
+ /* at this point we know n >= 0 */
bp += n;
- len -= n;
+ len -= (size_t)n;
} while (!newline && len);
*bp = '\0';
return bp - buf;