diff --git a/libc/Makefile b/libc/Makefile
index 02a5b458..83d3d051 100644
--- a/libc/Makefile
+++ b/libc/Makefile
@@ -155,6 +155,7 @@ arpa/inet/inet_addr.o \
arpa/inet/inet_ntoa.o \
arpa/inet/inet_ntop.o \
arpa/inet/inet_pton.o \
+basename.o \
calltrace.o \
canonicalize_file_name_at.o \
canonicalize_file_name.o \
@@ -168,6 +169,7 @@ $(CPUDIR)/fork.o \
$(CPUDIR)/signal.o \
$(CPUDIR)/syscall.o \
creat.o \
+dirname.o \
dispmsg_issue.o \
dlfcn.o \
dup2.o \
diff --git a/libc/basename.cpp b/libc/basename.cpp
new file mode 100644
index 00000000..f3c813d9
--- /dev/null
+++ b/libc/basename.cpp
@@ -0,0 +1,46 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2013.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C 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 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C 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 the Sortix C Library. If not, see .
+
+ basename.cpp
+ Returns the name part of a path.
+
+*******************************************************************************/
+
+#include
+#include
+
+char* basename(char* path)
+{
+ static char static_stuff[2];
+ if ( !path || !*path )
+ {
+ static_stuff[0] = '.';
+ static_stuff[1] = '\0';
+ return static_stuff;
+ }
+ size_t path_len = strlen(path);
+ while ( 2 <= path_len && path[path_len-1] == '/' )
+ path[--path_len] = '\0';
+ if ( strcmp(path, "/") == 0 )
+ return path;
+ char* last_slash = strchr(path, '/');
+ if ( !last_slash )
+ return path;
+ return last_slash + 1;
+}
diff --git a/libc/dirname.cpp b/libc/dirname.cpp
new file mode 100644
index 00000000..a1ace1ec
--- /dev/null
+++ b/libc/dirname.cpp
@@ -0,0 +1,47 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2013.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C 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 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C 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 the Sortix C Library. If not, see .
+
+ dirname.cpp
+ Returns the directory part of a path.
+
+*******************************************************************************/
+
+#include
+#include
+
+char* dirname(char* path)
+{
+ static char static_stuff[2];
+ if ( !path || !*path )
+ {
+ static_stuff[0] = '.';
+ static_stuff[1] = '\0';
+ return static_stuff;
+ }
+ size_t path_len = strlen(path);
+ while ( 2 <= path_len && path[path_len-1] == '/' )
+ path[--path_len] = '\0';
+ if ( strcmp(path, "/") == 0 )
+ return path;
+ char* last_slash = strchr(path, '/');
+ if ( !last_slash )
+ return dirname(NULL);
+ *last_slash = '\0';
+ return path;
+}
diff --git a/libc/include/libgen.h b/libc/include/libgen.h
new file mode 100644
index 00000000..59a2724a
--- /dev/null
+++ b/libc/include/libgen.h
@@ -0,0 +1,37 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2013.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C 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 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C 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 the Sortix C Library. If not, see .
+
+ libgen.h
+ What's left of some old pattern matching library.
+
+*******************************************************************************/
+
+#ifndef INCLUDE_LIBGEN_H
+#define INCLUDE_LIBGEN_H
+
+#include
+
+__BEGIN_DECLS
+
+char* dirname(char* path);
+char* basename(char* path);
+
+__END_DECLS
+
+#endif