MISC(3X)

NAME
make_string, make_pathname, argv_copy_and_clear, basename, dirname - miscellaneous functions

SYNOPSIS

#include "misc.h"

char *make_string( count, ... )
unsigned count ;

char *make_pathname( count, ... )
unsigned count ;

char **argv_copy_and_clear( argv, start, count )
char **argv ;
int start, count ;

char *dirname( path )
char *path ;

char *basename( path )
char *path ;

DESCRIPTION

This library contain miscellaneous functions, hence the name.

make_string() creates a string by catenating the list of strings passed as arguments. count indicates how many strings there are. Strings that are NULL pointers are ignored. make_string() returns malloc'ed memory.

make_pathname() creates a pathname by catenating the list of pathname components passed as arguments and inserting slashes between them. count indicates how many components there are. make_pathname() returns malloc'ed memory.

argv_copy_and_clear() creates a new argv array of size count, and fills it with the contents of argv from start up to start+count-1. The original argv entries in that range are cleared by filling them with SPACEs.

dirname() returns in a malloced string containing all but the last of component of path. There are 2 special cases: first when the path is "/", dirname() will return "/", and second, when the path does not contain any '/', dirname() will return ".".

basename() returns a pointer to the last component of path.

RETURN VALUES

make_string() returns a pointer to the new string. It returns NULL if count is 0.

make_pathname() returns a pointer to the new pathname. It returns NULL if count is 0.

argv_copy_and_clear() returns the new argv array. It returns NULL if malloc fails to allocate more memory.

dirname() returns a new string or NULL if malloc fails to allocate more memory.

basename() returns a pointer to the last component of path.

BUGS

The behavior of dirname() and basename() is undefined if they are given a zero-length string.