diff --git a/examples/Makefile b/examples/Makefile index 507be12..361dfd9 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -6,6 +6,7 @@ INCLUDE_PATH = ../include CFLAGS += -I$(INCLUDE_PATH) LDFLAGS = -L../src -lhexagram +STATIC = ../src/libhexagram.a EXAMPLES = capture convert pcapread replay @@ -13,8 +14,8 @@ RM = /bin/rm all: $(EXAMPLES) -$(EXAMPLES): %: %.c - $(CC) $(CFLAGS) $< -o $@ ../src/libhexagram.a +$(EXAMPLES): %: %.c $(STATIC) + $(CC) $(CFLAGS) $< -o $@ $(STATIC) clean: $(RM) -f $(EXAMPLES) diff --git a/examples/capture.c b/examples/capture.c index 16c43a3..2bed423 100644 --- a/examples/capture.c +++ b/examples/capture.c @@ -44,7 +44,7 @@ int main(int argc, char **argv) { goto error_capture_open; } } else if (argc == 3) { - if ((capture = hexagram_capture_open_file(argv[2], O_CREAT | O_WRONLY)) == NULL) { + if ((capture = hexagram_capture_open_file(argv[2], O_CREAT | O_TRUNC | O_WRONLY)) == NULL) { perror("hexagram_capture_open_file()"); goto error_capture_open; diff --git a/src/capture.c b/src/capture.c index 2171949..85f8d79 100644 --- a/src/capture.c +++ b/src/capture.c @@ -96,7 +96,7 @@ ssize_t hexagram_capture_read(hexagram_capture *capture, if ((len = read(capture->fd, &data, sizeof(data))) < 0) { goto error_io; - } else if (len < sizeof(data)) { + } else if (len && len < sizeof(data)) { goto error_io; } @@ -143,18 +143,18 @@ error_gettimeofday: int hexagram_capture_replay(hexagram_capture *capture, hexagram_can_if *can_if, float speed) { - ssize_t len; - uint32_t timestamp[2], usec_last = 0; struct can_frame frame; while (1) { - if ((len = hexagram_capture_read(capture, - ×tamp[0], - ×tamp[1], - &frame)) < 0) { + ssize_t len = hexagram_capture_read(capture, + ×tamp[0], + ×tamp[1], + &frame); + + if (len < 0) { goto error_io; } else if (len == 0) { break;