#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
* 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);
}
}