/* * This file is part of Pathfns * Copyright (C) 2002 Richard Kettlewell * * This 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 2.1 of the License, or (at your option) any later version. * * This 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _INCLUDED_PATHFNS_H # define _INCLUDED_PATHFNS_H #ifdef __cplusplus extern "C" { #endif char *agetcwd(void); /* Determine the path of the current directory, if it has one. * * The absolute path to the current directory is written into a buffer * of suitable size allocated with malloc(). On success a pointer to * the buffer is returned. On error a null pointer is returned. */ char *adirname(const char *path); /* Determine the directory name of PATH * * Normally this is everything up to (but not including) the final * sequence of one or more consecutive "/" characters in PATH. There * are a few special cases: * * 1) If there is no "/", then the directory name is ".". * * 2) if the only "/" characters are right at the start of the * string, the directory name is "/". * * The directory name is written into a buffer of suitable size * allocated with malloc(), and null-terminated. On success a pointer * to the buffer is returned. On error a null pointer is returned. */ char *abasename(const char *path); /* Determine the base name of PATH * * Normally this is everything after the final "/", but there are some * special cases: * * 1) If PATH consists entirely of a sequence of one or more "/" * characters then the base name is "/". * * 2) If there is no "/" then the base name is just PATH. * * The base name is written into a buffer of suitable size allocated * with malloc(), and null-terminated. On success a pointer to the * buffer is returned. On error a null pointer is returned. */ int pathsplit(const char *path, char **basenamep, char **dirnamep); /* Determine the directory name and base name of PATH * * This function is equivalent to calling both adirname() and * abasename(), except that the new names are written back via the 2nd * and 3rd arguments. If either of these is a null pointer then they * are not updated. * * On success, 0 is returned. On error, -1 is returned. */ char *arealpath(const char *path); /* Determine the real path name of PATH. * * A real path always has the following properties: * * 1) It is an absolute path, i.e. the first character is always "/". * * 2) It does not contain any components that are "." or ".." * * 3) It does not contain any doubled slashes ("//") * * 4) No component is a symbolic link. * * A component of PATH that does not exist is not modified. * * The new path is written into a buffer of suitable size allocated * with malloc(), and null-terminated. On success a pointer to the * buffer is returned. On error a null pointer is returned. */ char *areadlink(const char *path); /* Read a symbolic link. Unlike readlink(2) this does not require a * buffer size to be chosen, and guarantees a null terminator. */ #ifdef __cplusplus }; #endif #endif /* Local Variables: c-basic-offset:2 comment-column:40 End: */