From 65c28f72c1d6421db071006dcdacae04100098c0 Mon Sep 17 00:00:00 2001 From: Vojtech Horky Date: Thu, 3 Aug 2017 10:06:51 +0200 Subject: [PATCH] libposix: add dlfcn.h, stdbool.h and sys/time.h --- uspace/lib/posix/Makefile | 1 + uspace/lib/posix/include/posix/dlfcn.h | 56 +++++++++++++++++++++++++ uspace/lib/posix/include/posix/stdbool.h | 46 +++++++++++++++++++++ uspace/lib/posix/include/posix/sys/time.h | 45 ++++++++++++++++++++ uspace/lib/posix/source/dlfcn.c | 68 +++++++++++++++++++++++++++++++ 5 files changed, 216 insertions(+) create mode 100644 uspace/lib/posix/include/posix/dlfcn.h create mode 100644 uspace/lib/posix/include/posix/stdbool.h create mode 100644 uspace/lib/posix/include/posix/sys/time.h create mode 100644 uspace/lib/posix/source/dlfcn.c diff --git a/uspace/lib/posix/Makefile b/uspace/lib/posix/Makefile index 779b0133d..1a60a7d50 100644 --- a/uspace/lib/posix/Makefile +++ b/uspace/lib/posix/Makefile @@ -54,6 +54,7 @@ EXTRA_OUTPUT = $(FIXED_C_LIBRARY) $(FIXED_POSIX_LIBRARY) SOURCES = \ source/ctype.c \ + source/dlfcn.c \ source/errno.c \ source/fcntl.c \ source/fnmatch.c \ diff --git a/uspace/lib/posix/include/posix/dlfcn.h b/uspace/lib/posix/include/posix/dlfcn.h new file mode 100644 index 000000000..43cb48f2f --- /dev/null +++ b/uspace/lib/posix/include/posix/dlfcn.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2017 Vojtech Horky + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * - The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** @addtogroup libposix + * @{ + */ + +#ifndef POSIX_DLFCN_H_ +#define POSIX_DLFCN_H_ + +#ifndef __POSIX_DEF__ +#define __POSIX_DEF__(x) x +#endif + +#define RTLD_LAZY 1 +#define RTLD_NOW 2 +#define RTLD_GLOBAL 32 +#define RTLD_LOCAL 0 + + +extern void *__POSIX_DEF__(dlopen)(const char *, int); +extern void *__POSIX_DEF__(dlsym)(void *, const char *); +extern int __POSIX_DEF__(dlclose)(void *); +extern char *__POSIX_DEF__(dlerror)(void); + + +#endif + +/** + * @} + */ diff --git a/uspace/lib/posix/include/posix/stdbool.h b/uspace/lib/posix/include/posix/stdbool.h new file mode 100644 index 000000000..d09ead867 --- /dev/null +++ b/uspace/lib/posix/include/posix/stdbool.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2017 Vojtech Horky + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * - The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** @addtogroup libposix + * @{ + */ +/** @file + */ + +#ifndef POSIX_BOOL_H_ +#define POSIX_BOOL_H_ + +#define bool _Bool +#define false 0 +#define true 1 +#define __bool_true_false_are_defined 1 + +#endif + +/** @} + */ diff --git a/uspace/lib/posix/include/posix/sys/time.h b/uspace/lib/posix/include/posix/sys/time.h new file mode 100644 index 000000000..8b9abaeee --- /dev/null +++ b/uspace/lib/posix/include/posix/sys/time.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2017 Vojtech Horky + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * - The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** @addtogroup libposix + * @{ + */ + +#ifndef POSIX_SYS_TIME_H_ +#define POSIX_SYS_TIME_H_ + +#ifndef __POSIX_DEF__ +#define __POSIX_DEF__(x) x +#endif + +#include "libc/sys/time.h" + +#endif + +/** @} + */ diff --git a/uspace/lib/posix/source/dlfcn.c b/uspace/lib/posix/source/dlfcn.c new file mode 100644 index 000000000..f5cfb95fb --- /dev/null +++ b/uspace/lib/posix/source/dlfcn.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2017 Vojtech Horky + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * - The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** @addtogroup libposix + * @{ + */ + +#define LIBPOSIX_INTERNAL +#define __POSIX_DEF__(x) posix_##x + +#include "internal/common.h" +#include "posix/dlfcn.h" + +#include "libc/dlfcn.h" + +void *posix_dlopen(const char *filename, int flags) +{ + if (flags != 0) { + fprintf(stderr, "dlopen() not implemented with non-zero flags (%s:%d), something will NOT work.\n", __FILE__, __LINE__); + } + + return dlopen(filename, 0); +} + +void *posix_dlsym(void *handle, const char *symbol) +{ + return dlsym(handle, symbol); +} + +int posix_dlclose(void *handle) +{ + not_implemented(); + return 0; +} + +char *posix_dlerror(void) +{ + not_implemented(); + return (char *)"dlerror()"; +} + +/** @} + */ -- 2.11.4.GIT