/*
 *   Copyright (C) 1988-2006 Lucent Technologies Inc. and others.
 *   All Rights Reserved.
 */

/* get a file's base name from its path name */

#if BSD
#define	strrchr	rindex
char	*strrchr();
#else
#if ilinux
extern char *strrchr (__const char *__s, int __c);
#else
#include <string.h>
#endif
#endif

#if defined(__BORLANDC__) || defined(FOR_WIN32)
#define PATHDELIM '\\'
#else
#define PATHDELIM '/'
#endif

char *
mybasename(path)
char	*path;
{
	char	*s;
	
	if ((s = strrchr(path, PATHDELIM)) != 0) {
		return(s + 1);
	}
	return(path);
}

/* This is an alternative basename where the caller specifies the end
 * of the string - this aids faster searches of multiple levels of
 * a path e.g. the basename of the dirname...
 * mybasename_end(x,strlen(x)) is the same as mybasename(x)
 */

char *
mybasename_end(path,end)
char *path;
char *end;
{
	char *s = end - 1;

	if (path == end) return path;
	while (s > path && (*s != PATHDELIM)) --s;
	return (*s == PATHDELIM) ? s+1 : s;
}

