From 7709abbc1c9618cc9c8923024d7f9be8d5b034bb Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Tue, 14 Jul 2015 16:45:03 +0000 Subject: [PATCH] Damn Xan, you code like a BEAST O:) --- Makefile | 5 +++ configure | 95 ++++++++++++++++++++++++++++++++++++++++++++ include/patty/kiss.h | 4 +- src/Makefile | 29 ++++++++++++++ src/kiss.c | 19 ++++++--- 5 files changed, 145 insertions(+), 7 deletions(-) create mode 100644 Makefile create mode 100755 configure create mode 100644 src/Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e2ad0f5 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +all: + $(MAKE) -C src all + +clean: + $(MAKE) -C src clean diff --git a/configure b/configure new file mode 100755 index 0000000..0f748d2 --- /dev/null +++ b/configure @@ -0,0 +1,95 @@ +#! /bin/sh + +OS=`uname -s` +PREFIX=/usr/local +DEBUG=0 + +create_linux_config_h() { + cat < src/config.h +#ifndef _CONFIG_H +#define _CONFIG_H +#include +#define PATTY_INSTALL_PREFIX "$PREFIX" +#endif /* _CONFIG_H */ +EOF +} + +create_darwin_config_h() { + cat < src/config.h +#ifndef _CONFIG_H +#define _CONFIG_H +#include + +#ifdef __LITTLE_ENDIAN__ +#define __DO_SWAP_BYTES +#endif /* _DO_SWAP_BYTES */ +#define PATTY_INSTALL_PREFIX "$PREFIX" +#endif /* _CONFIG_H */ +EOF +} + +create_common_build_mk() { + if [ "$DEBUG" = 1 ]; then + cat < mk/build.mk +PREFIX = $PREFIX + +CGFLAGS = -g -fno-inline +EOF + else + cat < mk/build.mk +PREFIX = $PREFIX + +CGFLAGS = +EOF + fi +} + +create_linux_build_mk() { + create_common_build_mk $@ + + cat <<'EOF' >> mk/build.mk +LLFLAGS = -shared -Wl,-soname=$(SONAME) + +SONAME_SHORT = lib$(LIBNAME).so +SONAME = $(SONAME_SHORT).$(VERSION_MAJOR) +SONAME_FULL = $(SONAME_SHORT).$(VERSION) +EOF +} + +create_darwin_build_mk() { + create_common_build_mk $@ + + cat <<'EOF' >> mk/build.mk +LLFLAGS = -dynamiclib -current_version $(VERSION) + +STATIC = lib$(LIBNAME).a + +SONAME_SHORT = $(LIBNAME).dylib +SONAME = lib$(LIBNAME).$(VERSION_MAJOR).dylib +SONAME_FULL = lib$(LIBNAME).$(VERSION).dylib +EOF +} + +for arg in $@; do + case $arg in + "--enable-debug") + DEBUG=1 + ;; + esac +done + +if [ ! -d "mk" ]; then + mkdir -m 0755 mk +fi + +case $OS in + Linux) + create_linux_config_h + create_linux_build_mk + ;; + + Darwin) + create_darwin_config_h + create_darwin_build_mk + ;; +esac diff --git a/include/patty/kiss.h b/include/patty/kiss.h index 9c89070..f736284 100644 --- a/include/patty/kiss.h +++ b/include/patty/kiss.h @@ -25,8 +25,8 @@ enum patty_kiss_command { PATTY_KISS_RETURN = 0xff }; -int patty_kiss_read(int fd, void *buf, size_t *len, int *channel); +ssize_t patty_kiss_read(int fd, void *buf, size_t len, int *port); -int patty_kiss_write(int fd, const void *buf, size_t len, int channel); +ssize_t patty_kiss_write(int fd, const void *buf, size_t len, int port); #endif /* _PATTY_KISS_H */ diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..9dfe9c0 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,29 @@ +include ../mk/build.mk + +INCLUDE_PATH = ../include +HEADER_SUBDIR = birch + +CC = $(CROSS)cc +CFLAGS = $(CGFLAGS) -fPIC -Wall -O2 -I$(INCLUDE_PATH) +LDFLAGS = + +HEADERS = kiss.h ax25.h +OBJS = kiss.o + +PROGRAM = + +AR = $(CROSS)ar +RANLIB = $(CROSS)ranlib + +RM = /bin/rm +LN = /bin/ln +RMDIR = /bin/rmdir +INSTALL = /usr/bin/install + +all: $(OBJS) + +$(OBJS): %.o: %.c $(HEADERS_BUILD) + $(CC) $(CFLAGS) -c $< + +clean: + $(RM) -f $(OBJS) diff --git a/src/kiss.c b/src/kiss.c index 901b858..3972308 100644 --- a/src/kiss.c +++ b/src/kiss.c @@ -1,3 +1,8 @@ +#include +#include +#include +#include + #include enum kiss_flags { @@ -19,7 +24,7 @@ ssize_t patty_kiss_read(int fd, void *buf, size_t len, int *port) { for (i=0; i> 4; continue; @@ -94,13 +99,12 @@ ssize_t patty_kiss_write(int fd, const void *buf, size_t len, int port) { goto error_io; } - if (write_command(PATTY_KISS_DATA, port) < 0) { + if (write_command(fd, PATTY_KISS_DATA, port) < 0) { goto error_io; } for (i=0; i