libsysutils

changeset 1:c1323f9f202d

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 05 May 2015 05:51:56 +0300
parents a8277d8f687a
children 36936815cc92
files Makefile include/datapath.h include/sysutils.h src/datapath.c src/sysu_impl.h src/sysutils.c
diffstat 6 files changed, 56 insertions(+), 3 deletions(-) [+]
line diff
     1.1 --- a/Makefile	Thu Feb 19 01:33:54 2015 +0200
     1.2 +++ b/Makefile	Tue May 05 05:51:56 2015 +0300
     1.3 @@ -1,3 +1,5 @@
     1.4 +PREFIX ?= /usr/local
     1.5 +
     1.6  src = $(wildcard src/*.c)
     1.7  obj = $(src:.c=.o)
     1.8  name = sysutils
     1.9 @@ -11,7 +13,7 @@
    1.10  ifeq ($(sys), Darwin)
    1.11  	lib_so = lib$(name).dylib
    1.12  	shared = -dynamiclib
    1.13 -else ($(sys), Win32)
    1.14 +else ifeq ($(sys), Win32)
    1.15  	lib_so = $(name).dll
    1.16  	# TODO shared = ?
    1.17  else # any other unix
    1.18 @@ -22,6 +24,10 @@
    1.19  	pic = -fPIC
    1.20  endif
    1.21  
    1.22 +inc = -Iinclude -Isrc
    1.23 +
    1.24 +CFLAGS = -pedantic -Wall -g $(pic) $(inc)
    1.25 +
    1.26  .PHONY: all
    1.27  all: $(lib_so) $(lib_a)
    1.28  
    1.29 @@ -29,7 +35,7 @@
    1.30  	$(AR) rcs $@ $(obj)
    1.31  
    1.32  $(lib_so): $(obj)
    1.33 -	$(CC) -o $@ $(obj) $(LDFLAGS)
    1.34 +	$(CC) -o $@ $(shared) $(obj) $(LDFLAGS)
    1.35  
    1.36  .PHONY: clean
    1.37  clean:
     2.1 --- a/include/datapath.h	Thu Feb 19 01:33:54 2015 +0200
     2.2 +++ b/include/datapath.h	Tue May 05 05:51:56 2015 +0300
     2.3 @@ -10,7 +10,7 @@
     2.4  	SYSU_CURRENT_DIR	/* current working directory */
     2.5  };
     2.6  
     2.7 -const char *sysu_get_directory(sysu_dir_type type);
     2.8 +const char *sysu_get_directory(enum sysu_dir_type type);
     2.9  
    2.10  /* Writes the path to outpath, and returns the size of the path in bytes.
    2.11   * Call with len <= 0 and outpath == NULL to return required storage
     3.1 --- a/include/sysutils.h	Thu Feb 19 01:33:54 2015 +0200
     3.2 +++ b/include/sysutils.h	Tue May 05 05:51:56 2015 +0300
     3.3 @@ -4,4 +4,7 @@
     3.4  #include "datapath.h"
     3.5  #include "sysinfo.h"
     3.6  
     3.7 +int sysu_init(const char *appname, const char *inst_prefix);
     3.8 +void sysu_shutdown(void);
     3.9 +
    3.10  #endif	/* LIBSYSUTILS_H_ */
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/datapath.c	Tue May 05 05:51:56 2015 +0300
     4.3 @@ -0,0 +1,5 @@
     4.4 +#include "datapath.h"
     4.5 +
     4.6 +const char *sysu_get_directory(enum sysu_dir_type type)
     4.7 +{
     4.8 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/sysu_impl.h	Tue May 05 05:51:56 2015 +0300
     5.3 @@ -0,0 +1,10 @@
     5.4 +#ifndef SYSU_IMPL_H_
     5.5 +#define SYSU_IMPL_H_
     5.6 +
     5.7 +struct sysu_state {
     5.8 +	char *appname;
     5.9 +	char *prefix;
    5.10 +} sysu_state;
    5.11 +
    5.12 +
    5.13 +#endif	/* SYSU_IMPL_H_ */
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/sysutils.c	Tue May 05 05:51:56 2015 +0300
     6.3 @@ -0,0 +1,29 @@
     6.4 +#include <stdlib.h>
     6.5 +#include <string.h>
     6.6 +#include "sysutils.h"
     6.7 +#include "sysu_impl.h"
     6.8 +
     6.9 +int sysu_init(const char *appname, const char *inst_prefix)
    6.10 +{
    6.11 +	memset(&sysu_state, 0, sizeof sysu_state);
    6.12 +
    6.13 +	if(appname) {
    6.14 +		if(!(sysu_state.appname = strdup(appname))) {
    6.15 +			return -1;
    6.16 +		}
    6.17 +	}
    6.18 +	if(inst_prefix) {
    6.19 +		if(!(sysu_state.prefix = strdup(inst_prefix))) {
    6.20 +			free(sysu_state.appname);
    6.21 +			return -1;
    6.22 +		}
    6.23 +	}
    6.24 +
    6.25 +	return 0;
    6.26 +}
    6.27 +
    6.28 +void sysu_shutdown(void)
    6.29 +{
    6.30 +	free(sysu_state.appname);
    6.31 +	free(sysu_state.prefix);
    6.32 +}