libsysutils

changeset 0:a8277d8f687a

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 19 Feb 2015 01:33:54 +0200
parents
children c1323f9f202d
files .hgignore Makefile include/datapath.h include/sysinfo.h include/sysutils.h include/user.h
diffstat 6 files changed, 113 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.hgignore	Thu Feb 19 01:33:54 2015 +0200
     1.3 @@ -0,0 +1,3 @@
     1.4 +\.o$
     1.5 +\.d$
     1.6 +\.swp$
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/Makefile	Thu Feb 19 01:33:54 2015 +0200
     2.3 @@ -0,0 +1,57 @@
     2.4 +src = $(wildcard src/*.c)
     2.5 +obj = $(src:.c=.o)
     2.6 +name = sysutils
     2.7 +lib_a = lib$(name).a
     2.8 +
     2.9 +so_major = 0
    2.10 +so_minor = 1
    2.11 +
    2.12 +sys = $(shell uname -s | sed 's/MINGW32.*/Win32/')
    2.13 +
    2.14 +ifeq ($(sys), Darwin)
    2.15 +	lib_so = lib$(name).dylib
    2.16 +	shared = -dynamiclib
    2.17 +else ($(sys), Win32)
    2.18 +	lib_so = $(name).dll
    2.19 +	# TODO shared = ?
    2.20 +else # any other unix
    2.21 +	ldname = lib$(name).so
    2.22 +	soname = lib$(name).so.$(so_major)
    2.23 +	lib_so = lib$(name).so.$(so_major).$(so_minor)
    2.24 +	shared = -shared -Wl,-soname=$(soname)
    2.25 +	pic = -fPIC
    2.26 +endif
    2.27 +
    2.28 +.PHONY: all
    2.29 +all: $(lib_so) $(lib_a)
    2.30 +
    2.31 +$(lib_a): $(obj)
    2.32 +	$(AR) rcs $@ $(obj)
    2.33 +
    2.34 +$(lib_so): $(obj)
    2.35 +	$(CC) -o $@ $(obj) $(LDFLAGS)
    2.36 +
    2.37 +.PHONY: clean
    2.38 +clean:
    2.39 +	rm -f $(obj) $(lib_a) $(lib_so)
    2.40 +
    2.41 +.PHONY: install
    2.42 +install: all
    2.43 +	mkdir -p $(DESTDIR)$(PREFIX)/include $(DESTDIR)$(PREFIX)/lib
    2.44 +	@echo 'add header files'
    2.45 +	cp $(lib_a) $(DESTDIR)$(PREFIX)/lib/$(lib_a)
    2.46 +	cp $(lib_so) $(DESTDIR)$(PREFIX)/lib/$(lib_so)
    2.47 +	[ -n "$(soname)" ] && \
    2.48 +		cd $(DESTDIR)$(PREFIX) && \
    2.49 +		rm -f $(soname) $(ldname) && \
    2.50 +		ln -s $(lib_so) $(soname) && \
    2.51 +		ln -s $(soname) $(ldname) || true
    2.52 +
    2.53 +.PHONY: uninstall
    2.54 +uninstall:
    2.55 +	rm -f $(DESTDIR)$(PREFIX)/lib/$(lib_a)
    2.56 +	rm -f $(DESTDIR)$(PREFIX)/lib/$(lib_so)
    2.57 +	[ -n "$(soname)" ] && \
    2.58 +		rm -f $(DESTDIR)$(PREFIX)/lib/$(soname) && \
    2.59 +		rm -f $(DESTDIR)$(PREFIX)/lib/$(ldname) || \
    2.60 +		true
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/include/datapath.h	Thu Feb 19 01:33:54 2015 +0200
     3.3 @@ -0,0 +1,32 @@
     3.4 +#ifndef LIBSYSUTILS_DATAPATH_H_
     3.5 +#define LIBSYSUTILS_DATAPATH_H_
     3.6 +
     3.7 +enum sysu_dir_type {
     3.8 +	SYSU_DATA_DIR,		/* read-only assets directory */
     3.9 +	SYSU_STORAGE_DIR,	/* read-write persistent storage directory */
    3.10 +	SYSU_CONFIG_DIR,	/* configuration directory */
    3.11 +	SYSU_TMP_DIR,		/* temporary data directory */
    3.12 +	SYSU_HOME_DIR,		/* user's home directory */
    3.13 +	SYSU_CURRENT_DIR	/* current working directory */
    3.14 +};
    3.15 +
    3.16 +const char *sysu_get_directory(sysu_dir_type type);
    3.17 +
    3.18 +/* Writes the path to outpath, and returns the size of the path in bytes.
    3.19 + * Call with len <= 0 and outpath == NULL to return required storage
    3.20 + * size for the path.
    3.21 + */
    3.22 +int sysu_datapath(const char *inpath, char *outpath, int len);
    3.23 +
    3.24 +/* same as above, but stores the path to an internal static buffer,
    3.25 + * which will be overwritten or moved at the next call (thread unsafe).
    3.26 + */
    3.27 +const char *sysu_datapath_static(const char *inpath);
    3.28 +
    3.29 +/* same as above, but allocates storage for the returned path
    3.30 + * which must be freed by a call to sysu_free_datapath.
    3.31 + */
    3.32 +char *sysu_datapath_alloc(const char *inpath);
    3.33 +void sysu_free_datapath(char *p);
    3.34 +
    3.35 +#endif	/* LIBSYSUTILS_DATAPATH_H_ */
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/include/sysinfo.h	Thu Feb 19 01:33:54 2015 +0200
     4.3 @@ -0,0 +1,6 @@
     4.4 +#ifndef LIBSYSUTILS_SYSINFO_H_
     4.5 +#define LIBSYSUTILS_SYSINFO_H_
     4.6 +
     4.7 +int sysu_get_num_processors(void);
     4.8 +
     4.9 +#endif	/* LIBSYSUTILS_SYSINFO_H_ */
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/include/sysutils.h	Thu Feb 19 01:33:54 2015 +0200
     5.3 @@ -0,0 +1,7 @@
     5.4 +#ifndef LIBSYSUTILS_H_
     5.5 +#define LIBSYSUTILS_H_
     5.6 +
     5.7 +#include "datapath.h"
     5.8 +#include "sysinfo.h"
     5.9 +
    5.10 +#endif	/* LIBSYSUTILS_H_ */
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/include/user.h	Thu Feb 19 01:33:54 2015 +0200
     6.3 @@ -0,0 +1,8 @@
     6.4 +#ifndef LIBSYSUTILS_USER_H_
     6.5 +#define LIBSYSUTILS_USER_H_
     6.6 +
     6.7 +const char *sysu_username(void);
     6.8 +const char *sysu_realname(void);
     6.9 +const char *sysu_homedir(void);
    6.10 +
    6.11 +#endif	/* LIBSYSUTILS_USER_H_ */