# HG changeset patch # User John Tsiombikas # Date 1424302434 -7200 # Node ID a8277d8f687a5e1729d798d8fdae58f72c3960bb initial commit diff -r 000000000000 -r a8277d8f687a .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Thu Feb 19 01:33:54 2015 +0200 @@ -0,0 +1,3 @@ +\.o$ +\.d$ +\.swp$ diff -r 000000000000 -r a8277d8f687a Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Thu Feb 19 01:33:54 2015 +0200 @@ -0,0 +1,57 @@ +src = $(wildcard src/*.c) +obj = $(src:.c=.o) +name = sysutils +lib_a = lib$(name).a + +so_major = 0 +so_minor = 1 + +sys = $(shell uname -s | sed 's/MINGW32.*/Win32/') + +ifeq ($(sys), Darwin) + lib_so = lib$(name).dylib + shared = -dynamiclib +else ($(sys), Win32) + lib_so = $(name).dll + # TODO shared = ? +else # any other unix + ldname = lib$(name).so + soname = lib$(name).so.$(so_major) + lib_so = lib$(name).so.$(so_major).$(so_minor) + shared = -shared -Wl,-soname=$(soname) + pic = -fPIC +endif + +.PHONY: all +all: $(lib_so) $(lib_a) + +$(lib_a): $(obj) + $(AR) rcs $@ $(obj) + +$(lib_so): $(obj) + $(CC) -o $@ $(obj) $(LDFLAGS) + +.PHONY: clean +clean: + rm -f $(obj) $(lib_a) $(lib_so) + +.PHONY: install +install: all + mkdir -p $(DESTDIR)$(PREFIX)/include $(DESTDIR)$(PREFIX)/lib + @echo 'add header files' + cp $(lib_a) $(DESTDIR)$(PREFIX)/lib/$(lib_a) + cp $(lib_so) $(DESTDIR)$(PREFIX)/lib/$(lib_so) + [ -n "$(soname)" ] && \ + cd $(DESTDIR)$(PREFIX) && \ + rm -f $(soname) $(ldname) && \ + ln -s $(lib_so) $(soname) && \ + ln -s $(soname) $(ldname) || true + +.PHONY: uninstall +uninstall: + rm -f $(DESTDIR)$(PREFIX)/lib/$(lib_a) + rm -f $(DESTDIR)$(PREFIX)/lib/$(lib_so) + [ -n "$(soname)" ] && \ + rm -f $(DESTDIR)$(PREFIX)/lib/$(soname) && \ + rm -f $(DESTDIR)$(PREFIX)/lib/$(ldname) || \ + true diff -r 000000000000 -r a8277d8f687a include/datapath.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/datapath.h Thu Feb 19 01:33:54 2015 +0200 @@ -0,0 +1,32 @@ +#ifndef LIBSYSUTILS_DATAPATH_H_ +#define LIBSYSUTILS_DATAPATH_H_ + +enum sysu_dir_type { + SYSU_DATA_DIR, /* read-only assets directory */ + SYSU_STORAGE_DIR, /* read-write persistent storage directory */ + SYSU_CONFIG_DIR, /* configuration directory */ + SYSU_TMP_DIR, /* temporary data directory */ + SYSU_HOME_DIR, /* user's home directory */ + SYSU_CURRENT_DIR /* current working directory */ +}; + +const char *sysu_get_directory(sysu_dir_type type); + +/* Writes the path to outpath, and returns the size of the path in bytes. + * Call with len <= 0 and outpath == NULL to return required storage + * size for the path. + */ +int sysu_datapath(const char *inpath, char *outpath, int len); + +/* same as above, but stores the path to an internal static buffer, + * which will be overwritten or moved at the next call (thread unsafe). + */ +const char *sysu_datapath_static(const char *inpath); + +/* same as above, but allocates storage for the returned path + * which must be freed by a call to sysu_free_datapath. + */ +char *sysu_datapath_alloc(const char *inpath); +void sysu_free_datapath(char *p); + +#endif /* LIBSYSUTILS_DATAPATH_H_ */ diff -r 000000000000 -r a8277d8f687a include/sysinfo.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/sysinfo.h Thu Feb 19 01:33:54 2015 +0200 @@ -0,0 +1,6 @@ +#ifndef LIBSYSUTILS_SYSINFO_H_ +#define LIBSYSUTILS_SYSINFO_H_ + +int sysu_get_num_processors(void); + +#endif /* LIBSYSUTILS_SYSINFO_H_ */ diff -r 000000000000 -r a8277d8f687a include/sysutils.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/sysutils.h Thu Feb 19 01:33:54 2015 +0200 @@ -0,0 +1,7 @@ +#ifndef LIBSYSUTILS_H_ +#define LIBSYSUTILS_H_ + +#include "datapath.h" +#include "sysinfo.h" + +#endif /* LIBSYSUTILS_H_ */ diff -r 000000000000 -r a8277d8f687a include/user.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/user.h Thu Feb 19 01:33:54 2015 +0200 @@ -0,0 +1,8 @@ +#ifndef LIBSYSUTILS_USER_H_ +#define LIBSYSUTILS_USER_H_ + +const char *sysu_username(void); +const char *sysu_realname(void); +const char *sysu_homedir(void); + +#endif /* LIBSYSUTILS_USER_H_ */