1570af302Sopenharmony_ci#include <string.h>
2570af302Sopenharmony_ci#include <libgen.h>
3570af302Sopenharmony_ci
4570af302Sopenharmony_cichar *dirname(char *s)
5570af302Sopenharmony_ci{
6570af302Sopenharmony_ci	size_t i;
7570af302Sopenharmony_ci	if (!s || !*s) return ".";
8570af302Sopenharmony_ci	i = strlen(s)-1;
9570af302Sopenharmony_ci	for (; s[i]=='/'; i--) if (!i) return "/";
10570af302Sopenharmony_ci	for (; s[i]!='/'; i--) if (!i) return ".";
11570af302Sopenharmony_ci	for (; s[i]=='/'; i--) if (!i) return "/";
12570af302Sopenharmony_ci	s[i+1] = 0;
13570af302Sopenharmony_ci	return s;
14570af302Sopenharmony_ci}
15