~ft/npe

9e05fc749cb48540ee04371cd578f5fd8898b034 — Jacob Moody 1 year, 4 months ago 686729f
npe: add libgen.h
4 files changed, 55 insertions(+), 0 deletions(-)

A include/npe/libgen.h
A libnpe/basename.c
A libnpe/dirname.c
M libnpe/mkfile
A include/npe/libgen.h => include/npe/libgen.h +9 -0
@@ 0,0 1,9 @@
#ifndef _npe_libgen_h_
#define _npe_libgen_h_

#include <npe.h>

char *dirname(char *path);
char *basename(char *path);

#endif

A libnpe/basename.c => libnpe/basename.c +20 -0
@@ 0,0 1,20 @@
#include <libgen.h>

char*
basename(char *path)
{
	char *p;

	if(path == nil || path[0] == 0)
		return ".";
	if(path[0] != 0 && path[0] == '/' && path[1] == 0)
		return path;
	p = path + strlen(path);
	for(p--; p > path+1 && *p == '/'; p--)
		*p = 0;
	for(p--; p > path && *p != '/'; p--)
		;
	if(*p == '/')
		return p+1;
	return p;
}

A libnpe/dirname.c => libnpe/dirname.c +24 -0
@@ 0,0 1,24 @@
#include <libgen.h>

char*
dirname(char *path)
{
	char *p;

	if(path == nil || path[0] == 0)
		return ".";
	if(path[0] != 0 && path[0] == '/' && path[1] == 0)
		return path;
	p = path + strlen(path);
	for(p--; p > path+1 && *p == '/'; p--)
		*p = 0;
	for(p--; p > path && *p != '/'; p--)
		;
	if(*p == '/' && p == path)
		return "/";
	if(p == path)
		return ".";
	if(*p == '/')
		*p = 0;
	return path;
}

M libnpe/mkfile => libnpe/mkfile +2 -0
@@ 11,8 11,10 @@ HFILES=\
OFILES=\
	_main.$O\
	_npe.$O\
	basename.$O\
	closedir.$O\
	dirfd.$O\
	dirname.$O\
	exp2.$O\
	fstatat.$O\
	fts_children.$O\