summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2012-12-11 18:17:36 +0100
committerChristian Pointner <equinox@spreadspace.org>2012-12-11 18:17:36 +0100
commit85bd1827cc6368644e088042f29194b438b041d9 (patch)
treeddf3ca5682ae431300404fada3904f7fce4e906d
parentupdated configure to use git instead of svn (diff)
added support for clang
fixed issues with gcc -Wall
-rw-r--r--README3
-rwxr-xr-xsrc/configure19
-rw-r--r--src/daemon.h3
-rw-r--r--src/datatypes.h1
-rw-r--r--src/gcsd.c4
-rw-r--r--src/l_tcp.c14
-rw-r--r--src/l_util.c2
-rw-r--r--src/log.c2
-rw-r--r--src/sig_handler.c2
-rw-r--r--tools/bin2c.lua4
10 files changed, 38 insertions, 16 deletions
diff --git a/README b/README
index 5b26943..59e2f62 100644
--- a/README
+++ b/README
@@ -22,6 +22,9 @@ core:
lua5.1
liblua5.1-0-dev
+if you want clang as compiler
+ clang
+
if you want to rebuild the manpage:
asciidoc
diff --git a/src/configure b/src/configure
index c495453..fe013b1 100755
--- a/src/configure
+++ b/src/configure
@@ -34,8 +34,7 @@
TARGET=`uname -s`
EBUILD_COMPAT=0
-CFLAGS='-g -O2'
-LDFLAGS='-g -Wall -O2 -lm'
+USE_CLANG=0
LUA_DIR=''
LUA=''
@@ -62,6 +61,7 @@ print_usage() {
echo " --examplesdir=<DIR> the path to the examples files (default: $PREFIX/share/examples)"
echo " --no-examples dont't install example files"
echo " --with-lua=<DIR> use this lua tree instead of system default"
+ echo " --use-clang use clang/llvm as compiler/linker"
}
for arg
@@ -70,6 +70,9 @@ do
--target=*)
TARGET=${arg#--target=}
;;
+ --use-clang)
+ USE_CLANG=1
+ ;;
--prefix=*)
PREFIX=${arg#--prefix=}
;;
@@ -119,6 +122,16 @@ if [ -n "$ERRORS" ] && [ $EBUILD_COMPAT -ne 1 ]; then
exit 1
fi
+if [ $USE_CLANG -eq 0 ]; then
+ CFLAGS='-g -Wall -O2'
+ LDFLAGS='-g -Wall -O2 -lm'
+ COMPILER='gcc'
+else
+ CFLAGS='-g -O2'
+ LDFLAGS='-g -O2 -lm'
+ COMPILER='clang'
+fi
+
rm -f config.h
rm -f include.mk
case $TARGET in
@@ -238,7 +251,7 @@ cat > include.mk <<EOF
# use ./configure instead
TARGET := '$TARGET'
-CC := gcc
+CC := $COMPILER
CFLAGS := $CFLAGS
LDFLAGS := $LDFLAGS
LUA := '$LUA'
diff --git a/src/daemon.h b/src/daemon.h
index 1b8e7d6..5723e04 100644
--- a/src/daemon.h
+++ b/src/daemon.h
@@ -40,6 +40,8 @@
#include <sys/wait.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <errno.h>
+#include <string.h>
struct priv_info_struct {
struct passwd* pw_;
@@ -119,6 +121,7 @@ int do_chroot(const char* chrootdir)
log_printf(ERROR, "can't change to /: %s", strerror(errno));
return -1;
}
+ return 0;
}
void daemonize()
diff --git a/src/datatypes.h b/src/datatypes.h
index dca12b1..3a8addb 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -33,6 +33,7 @@
#ifndef GCSD_datatypes_h_INCLUDED
#define GCSD_datatypes_h_INCLUDED
+#include <stddef.h>
#include <stdint.h>
struct buffer_struct {
diff --git a/src/gcsd.c b/src/gcsd.c
index b4beef9..1d7d163 100644
--- a/src/gcsd.c
+++ b/src/gcsd.c
@@ -54,8 +54,8 @@
#include "daemon.h"
#endif
-extern const uint8_t gcsd_lua_bytecode[];
-extern const uint32_t gcsd_lua_bytecode_len;
+extern const char gcsd_lua_bytecode[];
+extern const size_t gcsd_lua_bytecode_len;
#define LUA_MAIN_LOOP_FUNC "main_loop"
diff --git a/src/l_tcp.c b/src/l_tcp.c
index 9418ea5..d96742c 100644
--- a/src/l_tcp.c
+++ b/src/l_tcp.c
@@ -30,13 +30,15 @@
* along with gcsd. If not, see <http://www.gnu.org/licenses/>.
*/
+#define _GNU_SOURCE
+#include <stdio.h>
+
#include <lua.h>
#include <lauxlib.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
-#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
@@ -59,7 +61,7 @@ typedef struct {
static tcp_endpoint_t* newtcpendudata(lua_State *L)
{
tcp_endpoint_t* end = (tcp_endpoint_t*)lua_newuserdata(L, sizeof(tcp_endpoint_t));
- memset(end, 0, sizeof(end));
+ memset(end, 0, sizeof(*end));
luaL_newmetatable(L, LUA_TCP_UDATA_NAME);
lua_setmetatable(L, -2);
return end;
@@ -67,7 +69,6 @@ static tcp_endpoint_t* newtcpendudata(lua_State *L)
static char* tcp_endpoint_to_string(tcp_endpoint_t* e)
{
- size_t addrstr_len = 0;
char addrstr[INET6_ADDRSTRLEN + 1], portstr[6], *ret;
char addrport_sep = ':';
@@ -76,12 +77,13 @@ static char* tcp_endpoint_to_string(tcp_endpoint_t* e)
case AF_INET: addrport_sep = ':'; break;
case AF_INET6: addrport_sep = '.'; break;
case AF_UNSPEC: return NULL;
- default: asprintf(&ret, "unknown address type"); return ret;
+ default: return strdup("unknown address type");
}
int errcode = getnameinfo((struct sockaddr *)&(e->addr_), e->len_, addrstr, sizeof(addrstr), portstr, sizeof(portstr), NI_NUMERICHOST | NI_NUMERICSERV);
if (errcode != 0) return NULL;
- asprintf(&ret, "%s%c%s", addrstr, addrport_sep ,portstr);
+ int len = asprintf(&ret, "%s%c%s", addrstr, addrport_sep ,portstr);
+ if(len == -1) return NULL;
return ret;
}
@@ -325,7 +327,7 @@ static int l_tcp_connect(lua_State *L)
{
int fd = luaL_checkint(L, 1);
int error = 0;
- int len = sizeof(error);
+ socklen_t len = sizeof(error);
if(getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len)==-1) {
log_printf(ERROR, "error on getsockopt(): %s", strerror(errno));
lua_pushnil(L);
diff --git a/src/l_util.c b/src/l_util.c
index 3b174b6..dbe43a5 100644
--- a/src/l_util.c
+++ b/src/l_util.c
@@ -214,7 +214,7 @@ void free_ptrptr(char** ptrptr)
free(ptrptr);
}
-static int child_add(lua_State *L, pid_t pid, int fd)
+static void child_add(lua_State *L, pid_t pid, int fd)
{
lua_getglobal(L, LUA_UTILLIBNAME);
lua_getfield(L, -1, LUA_UTILCHLIDRENNAME);
diff --git a/src/log.c b/src/log.c
index 772d4ca..3797092 100644
--- a/src/log.c
+++ b/src/log.c
@@ -250,7 +250,7 @@ void log_print_hex_dump(log_prio_t prio, const uint8_t* buf, uint32_t len)
int offset = snprintf(msg, MSG_LENGTH_MAX, "dump(%d): ", len);
if(offset < 0)
return;
- uint8_t* ptr = &msg[offset];
+ char* ptr = &msg[offset];
for(i=0; i < len; i++) {
if(((i+1)*3) >= (MSG_LENGTH_MAX - offset))
diff --git a/src/sig_handler.c b/src/sig_handler.c
index bdd92e2..45a513c 100644
--- a/src/sig_handler.c
+++ b/src/sig_handler.c
@@ -36,7 +36,7 @@
#include "sig_handler.h"
#include <errno.h>
-
+#include <string.h>
#ifndef WINVER
diff --git a/tools/bin2c.lua b/tools/bin2c.lua
index 6a6eefb..879c783 100644
--- a/tools/bin2c.lua
+++ b/tools/bin2c.lua
@@ -51,9 +51,9 @@ io.write([=[
#include "datatypes.h"
-const uint8_t ]=] , c_var_name, [=[[]={
+const char ]=] , c_var_name, [=[[]={
]=], dump(content), [=[
};
-const uint32_t ]=] , c_var_name, [=[_len = sizeof(]=] , c_var_name, [=[);
+const size_t ]=] , c_var_name, [=[_len = sizeof(]=] , c_var_name, [=[);
]=])