]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: remove basename() dependency 9845/head
authorJohn Coyle <dx9err@gmail.com>
Sat, 27 Feb 2016 19:06:09 +0000 (14:06 -0500)
committerJohn Coyle <dx9err@gmail.com>
Thu, 23 Jun 2016 18:07:23 +0000 (14:07 -0400)
Alpine linux only provides POSIX interface. Current code does not adhere to POSIX basename(char*) expectation.

http://pubs.opengroup.org/onlinepubs/9699919799/

Signed-off-by: John Coyle <dx9err@gmail.com>
src/common/config.cc

index 4bc0a3bc3645a84e2ccd8d6724dfad3d3e486138..ac2a407bbc28caf306a77abb20de8d0be421b2a6 100644 (file)
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
-#if defined(__FreeBSD__)
-/* FreeBSD/Clang requires basename() whereas Linux preffers the version in <string.h> */
-#include <libgen.h>
-#endif
 
 /* Don't use standard Ceph logging in this file.
  * We can't use logging until it's initialized, and a lot of the necessary
@@ -267,18 +263,17 @@ int md_config_t::parse_config_files_impl(const std::list<std::string> &conf_file
      * If cluster name is not set yet, use the prefix of the
      * basename of configuration file as cluster name.
      */
-    const char *fn = c->c_str();
-    std::string name(basename(fn));
-    int pos = name.find(".conf");
-    if (pos < 0) {
-      /*
-       * If the configuration file does not follow $cluster.conf
-       * convention, we do the last try and assign the cluster to
-       * 'ceph'.
-       */
-      cluster = "ceph";
+    auto start = c->rfind('/') + 1;
+    auto end = c->find(".conf", start);
+    if (end == c->npos) {
+        /*
+         * If the configuration file does not follow $cluster.conf
+         * convention, we do the last try and assign the cluster to
+         * 'ceph'.
+         */
+        cluster = "ceph";
     } else {
-      cluster = name.substr(0, pos);      
+      cluster = c->substr(start, end - start);
     }
   }