compatibility BUGFIX detection of get_current_dir_name() presence
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 91a2ff3..2ffa4b7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -80,6 +80,11 @@
     set(COMPILER_PACKED_ATTR "")
 endif()
 
+list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
+check_symbol_exists(get_current_dir_name unistd.h HAVE_GET_CURRENT_DIR_NAME)
+check_symbol_exists(vdprintf stdio.h HAVE_VDPRINTF)
+check_symbol_exists(strnstr string.h HAVE_STRNSTR)
+
 include_directories(${PROJECT_BINARY_DIR}/src ${PROJECT_SOURCE_DIR}/src)
 configure_file(${PROJECT_SOURCE_DIR}/src/config.h.in ${PROJECT_BINARY_DIR}/src/config.h @ONLY)
 
@@ -220,10 +225,6 @@
     src/log.h
     src/set.h)
 
-list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
-check_symbol_exists(vdprintf stdio.h HAVE_VDPRINTF)
-check_symbol_exists(strnstr string.h HAVE_STRNSTR)
-
 # create static libyang library
 if(ENABLE_STATIC)
     add_definitions(-DSTATIC)
diff --git a/src/common.c b/src/common.c
index 5e19200..bdb671d 100644
--- a/src/common.c
+++ b/src/common.c
@@ -143,22 +143,6 @@
     [LYS_DEV_REPLACE] = "replace",
 };
 
-#ifndef  __USE_GNU
-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
-
 void *
 ly_realloc(void *ptr, size_t size)
 {
diff --git a/src/common.h b/src/common.h
index df65edc..41b1444 100644
--- a/src/common.h
+++ b/src/common.h
@@ -18,7 +18,6 @@
 #define _DEFAULT_SOURCE
 #define _GNU_SOURCE
 
-#include <features.h>
 #include <pthread.h>
 #include <stdc-predef.h>
 #include <stddef.h>
@@ -56,17 +55,18 @@
  */
 #define API __attribute__((visibility("default")))
 
-#ifndef  __USE_GNU
-/*
- * If we don't have GNU extension, implement these function on your own
- */
-char *get_current_dir_name(void);
-#endif
 
 /******************************************************************************
  * 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
diff --git a/src/compat.c b/src/compat.c
index 7c4d660..c877ceb 100644
--- a/src/compat.c
+++ b/src/compat.c
@@ -15,9 +15,9 @@
 #include "common.h"
 
 #include <string.h>
+#include <unistd.h>
 
 #ifndef HAVE_STRNSTR
-
 char *
 strnstr(const char *s, const char *find, size_t slen)
 {
@@ -38,5 +38,20 @@
     }
     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 3f107d9..a625b8b 100644
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -17,6 +17,8 @@
 
 #cmakedefine APPLE
 
+#cmakedefine HAVE_GET_CURRENT_DIR_NAME
+
 #cmakedefine HAVE_VDPRINTF
 
 #cmakedefine HAVE_STRNSTR