compat FEATURE use standalone compat "library"
diff --git a/src/common.h b/src/common.h
index a53f8c1..0c458a8 100644
--- a/src/common.h
+++ b/src/common.h
@@ -57,26 +57,6 @@
/******************************************************************************
- * Compatibility functions
- *****************************************************************************/
-
-#ifndef HAVE_GET_CURRENT_DIR_NAME
-/**
- * @brief Return a malloc'd string containing the current directory name.
- */
-char *get_current_dir_name(void);
-#endif
-
-#ifndef HAVE_STRNSTR
-/**
- * @brief Find the first occurrence of find in s, where the search is limited to the
- * first slen characters of s.
- */
-char *strnstr(const char *s, const char *find, size_t slen);
-#endif
-
-
-/******************************************************************************
* Logger
*****************************************************************************/
@@ -271,7 +251,7 @@
#define LY_CTX_CHANGED_TREE 0x8000 /**< Deviation changed tree of a module(s) in the context, it is necessary to recompile
leafref paths, default values and must/when expressions to check that they are still valid */
-/**@} contextflags */
+/** @} contextflags */
/**
* @brief Try to find submodule in the context. Submodules are present only in the parsed (lysp_) schema trees, if only
diff --git a/src/compat.c b/src/compat.c
deleted file mode 100644
index 9a12537..0000000
--- a/src/compat.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- * @file compat.c
- * @author Michal Vasko <mvasko@cesnet.cz>
- * @brief Compatibility functions - implemented basic functions which are not available on all the platforms.
- *
- * Copyright (c) 2018 CESNET, z.s.p.o.
- *
- * This source code is licensed under BSD 3-Clause License (the "License").
- * You may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://opensource.org/licenses/BSD-3-Clause
- */
-
-#include "common.h"
-
-#ifndef HAVE_GET_CURRENT_DIR_NAME
-# include <limits.h>
-# include <unistd.h>
-#endif
-#include <string.h>
-
-#include "config.h"
-
-#ifndef HAVE_STRNSTR
-char *
-strnstr(const char *s, const char *find, size_t slen)
-{
- char c, sc;
- size_t len;
-
- if ((c = *find++) != '\0') {
- len = strlen(find);
- do {
- do {
- if (slen-- < 1 || (sc = *s++) == '\0')
- return (NULL);
- } while (sc != c);
- if (len > slen)
- return (NULL);
- } while (strncmp(s, find, len) != 0);
- s--;
- }
- return ((char *)s);
-}
-#endif
-
-#ifndef HAVE_GET_CURRENT_DIR_NAME
-char *
-get_current_dir_name(void)
-{
- char tmp[PATH_MAX];
- char *retval;
-
- if (getcwd(tmp, sizeof(tmp))) {
- retval = strdup(tmp);
- LY_CHECK_ERR_RET(!retval, LOGMEM(NULL), NULL);
- return retval;
- }
- return NULL;
-}
-#endif
diff --git a/src/config.h.in b/src/config.h.in
index a625b8b..eccc1e9 100644
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -15,14 +15,6 @@
#ifndef LY_CONFIG_H_
#define LY_CONFIG_H_
-#cmakedefine APPLE
-
-#cmakedefine HAVE_GET_CURRENT_DIR_NAME
-
-#cmakedefine HAVE_VDPRINTF
-
-#cmakedefine HAVE_STRNSTR
-
/**
* @brief Compiler flag for unused function attributes
*/
diff --git a/src/parser.c b/src/parser.c
index a7f1200..a394f0d 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -25,6 +25,7 @@
#include <unistd.h>
#include "common.h"
+#include "compat.h"
#include "dict.h"
#include "log.h"
#include "parser_internal.h"
@@ -239,8 +240,10 @@
lys_parser_fill_filepath(struct ly_ctx *ctx, struct ly_in *in, const char **filepath)
{
char path[PATH_MAX];
+#ifndef __APPLE__
char proc_path[32];
int len;
+#endif
LY_CHECK_ARG_RET(NULL, ctx, in, filepath, );
if (*filepath) {
diff --git a/src/parser_json.c b/src/parser_json.c
index e3e1bdf..3163693 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -18,6 +18,7 @@
#include <string.h>
#include "common.h"
+#include "compat.h"
#include "config.h"
#include "context.h"
diff --git a/src/path.c b/src/path.c
index 23e0cfb..e72485b 100644
--- a/src/path.c
+++ b/src/path.c
@@ -20,6 +20,7 @@
#include <stdlib.h>
#include "common.h"
+#include "compat.h"
#include "log.h"
#include "plugins_types.h"
#include "tree_data_internal.h"
diff --git a/src/plugins_types.c b/src/plugins_types.c
index a41239d..b26f16b 100644
--- a/src/plugins_types.c
+++ b/src/plugins_types.c
@@ -24,6 +24,7 @@
#include <string.h>
#include "common.h"
+#include "compat.h"
#include "config.h"
#include "dict.h"
#include "path.h"
diff --git a/src/printer.c b/src/printer.c
index e56a252..cbedb86 100644
--- a/src/printer.c
+++ b/src/printer.c
@@ -25,7 +25,7 @@
#include <unistd.h>
#include "common.h"
-#include "config.h"
+#include "compat.h"
#include "log.h"
#include "plugins_types.h"
#include "printer_data.h"
@@ -212,34 +212,8 @@
*out = calloc(1, sizeof **out);
LY_CHECK_ERR_RET(!*out, LOGMEM(NULL), LY_EMEM);
-
-#ifdef HAVE_VDPRINTF
(*out)->type = LY_OUT_FD;
(*out)->method.fd = fd;
-#else
- /* Without vdfprintf(), change the printing method to printing to a FILE stream.
- * To preserve the original file descriptor, duplicate it and use it to open file stream. */
- (*out)->type = LY_OUT_FDSTREAM;
- (*out)->method.fdstream.fd = fd;
-
- fd = dup((*out)->method.fdstream.fd);
- if (fd < 0) {
- LOGERR(NULL, LY_ESYS, "Unable to duplicate provided file descriptor (%d) for printing the output (%s).",
- (*out)->method.fdstream.fd, strerror(errno));
- free(*out);
- *out = NULL;
- return LY_ESYS;
- }
- (*out)->method.fdstream.f = fdopen(fd, "a");
- if (!(*out)->method.fdstream.f) {
- LOGERR(NULL, LY_ESYS, "Unable to open provided file descriptor (%d) for printing the output (%s).",
- (*out)->method.fdstream.fd, strerror(errno));
- free(*out);
- *out = NULL;
- close(fd);
- return LY_ESYS;
- }
-#endif
return LY_SUCCESS;
}
@@ -509,15 +483,8 @@
switch (out->type) {
case LY_OUT_FD:
-#ifdef HAVE_VDPRINTF
count = vdprintf(out->method.fd, format, ap);
break;
-#else
- /* never should be here since ly_out_fd() is supposed to set type to LY_OUT_FDSTREAM in case vdprintf() is missing */
- LOGINT(NULL);
- va_end(ap);
- return -LY_EINT;
-#endif
case LY_OUT_FDSTREAM:
case LY_OUT_FILEPATH:
case LY_OUT_FILE:
diff --git a/src/tree_data.c b/src/tree_data.c
index 5942b09..8125bb1 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -28,6 +28,7 @@
#include <unistd.h>
#include "common.h"
+#include "compat.h"
#include "config.h"
#include "context.h"
#include "dict.h"
diff --git a/src/tree_schema.c b/src/tree_schema.c
index f15340a..d63ab06 100644
--- a/src/tree_schema.c
+++ b/src/tree_schema.c
@@ -27,6 +27,7 @@
#include <unistd.h>
#include "common.h"
+#include "compat.h"
#include "context.h"
#include "dict.h"
#include "log.h"
diff --git a/src/tree_schema_compile.c b/src/tree_schema_compile.c
index bb70f31..1cfba45 100644
--- a/src/tree_schema_compile.c
+++ b/src/tree_schema_compile.c
@@ -23,6 +23,7 @@
#include <string.h>
#include "common.h"
+#include "compat.h"
#include "context.h"
#include "dict.h"
#include "log.h"
diff --git a/src/xml.c b/src/xml.c
index c188384..b4670f6 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -25,6 +25,7 @@
#include <sys/types.h>
#include "common.h"
+#include "compat.h"
#include "dict.h"
#include "printer.h"
#include "tree.h"
diff --git a/src/xpath.c b/src/xpath.c
index 1a13f1f..2b2dcbc 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -29,6 +29,7 @@
#include <string.h>
#include "common.h"
+#include "compat.h"
#include "context.h"
#include "dict.h"
#include "hash_table.h"