Author | Jamozed <[email protected]> |
Date | 2020-08-04 21:19:05 |
Commit | b16fdab1ee5caf7470a86f842dfe5fea945d33a4 |
Parent | 5e04987bc5a288fcafccfe0fbfe5e8b13c18661b |
meta: Replace libokv with local library
Diffstat
M | .gitignore | | | 10 | +++++----- |
D | .gitmodules | | | 3 | --- |
M | CMakeLists.txt | | | 12 | +++++++----- |
A | src/lib/error.c | | | 58 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | src/lib/error.h | | | 46 | ++++++++++++++++++++++++++++++++++++++++++++++ |
5 files changed, 116 insertions, 13 deletions
diff --git a/.gitignore b/.gitignore index 2254195..e01f885 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -.clangd/ -bin/ -build/ -compile_commands.json -lib/ +/.clangd/ +/bin/ +/build/ +/compile_commands.json +/lib/ diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index dc1733b..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "ext/libokv"] - path = ext/libokv - url = https://git.omkov.net/Jamozed/libokv diff --git a/CMakeLists.txt b/CMakeLists.txt index 004389c..ce2b49b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,15 +5,17 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.12) PROJECT(coreutils C) SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) -SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin) - -ADD_SUBDIRECTORY(ext/libokv) +SET(CMAKE_STATIC_LIBRARY_PREFIX "") INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/ext) -INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/ext/libokv/include) +INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/lib) + +FILE(GLOB LIBSRC ${PROJECT_SOURCE_DIR}/src/lib/*) + +ADD_LIBRARY(lib STATIC ${LIBSRC}) -LINK_LIBRARIES(libokv.a) +LINK_LIBRARIES(lib) ADD_EXECUTABLE(basename ${PROJECT_SOURCE_DIR}/src/basename.c) ADD_EXECUTABLE(cat ${PROJECT_SOURCE_DIR}/src/cat.c) diff --git a/ext/libokv b/ext/libokv deleted file mode 160000 index 239f4af..0000000 --- a/ext/libokv +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 239f4af50464f31a739bc81ea3de2f9fd0de3688 diff --git a/src/lib/error.c b/src/lib/error.c new file mode 100644 index 0000000..00f0f21 --- /dev/null +++ b/src/lib/error.c @@ -0,0 +1,58 @@ +// error.c +// Error source file for OMKOV lib +// Copyright (C) 2020, Jakob Wakeling +// All rights reserved. + +/* +OMKOV Permissive Licence, version 1.0 + +Copyright (C) 2020, Jakob Wakeling +All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal with +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimers. +* Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimers in the documentation and/or + other materials provided with the distribution. +* Neither the names of the copyright holders, nor the names of its contributors + may be used to endorse or promote products derived from this Software without + specific prior written permission. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT +HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. +*/ + +#include "error.h" + +#include <errno.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +char *A0 = NULL; + +void error(int status, const char *format, ...) { + fflush(stdout); if (A0) { fputs(A0, stderr); fputs(": ", stderr); } + va_list ap; va_start(ap, format); vfprintf(stderr, format, ap); va_end(ap); + fputc('\n', stderr); exit(status); +} + +void warn(const char *format, ...) { + fflush(stdout); if (A0) { fputs(A0, stderr); fputs(": ", stderr); } + va_list ap; va_start(ap, format); vfprintf(stderr, format, ap); va_end(ap); + fputc('\n', stderr); return; +} + +char *serr(void) { return strerror(errno); } diff --git a/src/lib/error.h b/src/lib/error.h new file mode 100644 index 0000000..13b59b1 --- /dev/null +++ b/src/lib/error.h @@ -0,0 +1,46 @@ +// error.h +// Error header file for OMKOV lib +// Copyright (C) 2020, Jakob Wakeling +// All rights reserved. + +/* +OMKOV Permissive Licence, version 1.0 + +Copyright (C) 2020, Jakob Wakeling +All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal with +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimers. +* Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimers in the documentation and/or + other materials provided with the distribution. +* Neither the names of the copyright holders, nor the names of its contributors + may be used to endorse or promote products derived from this Software without + specific prior written permission. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT +HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. +*/ + +#ifndef OMKOV_LIB_ERROR_H_38W06M3W +#define OMKOV_LIB_ERROR_H_38W06M3W + +extern char *A0; + +extern void error(int status, const char *format, ...); +extern void warn(const char *format, ...); + +extern char *serr(void); + +#endif // OMKOV_LIB_ERROR_H_38W06M3W