summarylogtreecommitdiffstats
path: root/basename-impl.h
diff options
context:
space:
mode:
authorGonzalo Exequiel Pedone2024-03-20 16:21:09 -0300
committerGonzalo Exequiel Pedone2024-03-20 16:21:09 -0300
commit37e804a2f9c4a0d232e30c03f556a7233db551b5 (patch)
tree64466d24dd75700d499cf542cdcfb96e39e2432d /basename-impl.h
parent469d4cf288d70928f76ec3cb25f5a4abc3afc5a3 (diff)
downloadaur-android-aarch64-kmod.tar.gz
Define basename() for API < 23.
Diffstat (limited to 'basename-impl.h')
-rw-r--r--basename-impl.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/basename-impl.h b/basename-impl.h
new file mode 100644
index 000000000000..6218ddd1dff1
--- /dev/null
+++ b/basename-impl.h
@@ -0,0 +1,52 @@
+/*
+ * libkmod - interface to kernel module operations
+ *
+ * Copyright (C) 2024 Gonzalo Exequiel Pedone. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+#ifndef _BASENAME_IMPL_H_
+#define _BASENAME_IMPL_H_
+
+#include <string.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+inline char *basename(char *path)
+{
+ int i;
+ int len;
+ int last;
+
+ if (path == NULL)
+ return NULL;
+
+ len = strlen(path);
+ last = len - 1;
+
+ for (i = last; i >= 0; i--)
+ if (*(path + i) == '/')
+ return path + i + 1;
+
+ return path + len;
+}
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+#endif