/* Library for handling pathnames * * pathnames.h * * (C) 2006 Sunrise Telephone Systems Ltd. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * * In countries and territories where the above no-warranty disclaimer is * not permissible by applicable law, the following terms apply: * * NO PERMISSION TO USE THE SOFTWARE IS GRANTED AND THE SOFTWARE MUST NOT BE * USED AT ALL IN SUCH COUNTRIES AND TERRITORIES WHERE THE ABOVE NO-WARRANTY * DISCLAIMER IS NOT PERMISSIBLE AND INVALIDATED BY APPLICABLE LAW. HOWEVER, * THE COPYRIGHT HOLDERS HEREBY WAIVE THEIR RIGHT TO PURSUE OFFENDERS AS LONG * AS THEY OTHERWISE ABIDE BY THE TERMS OF THE LICENSE AS APPLICABLE FOR USE * OF THE SOFTWARE IN COUNTRIES AND TERRITORIES WHERE THE ABOVE NO-WARRANTY * DISCLAIMER IS PERMITTED BY APPLICABLE LAW. THIS WAIVER DOES NOT CONSTITUTE * A LICENSE TO USE THE SOFTWARE IN COUNTRIES AND TERRITORIES WHERE THE ABOVE * NO-WARRANTY DISCLAIMER IS NOT PERMISSIBLE AND INVALIDATED BY APPLICABLE * LAW. ANY LIABILITY OF ANY KIND IS CATEGORICALLY RULED OUT AT ALL TIMES. */ // -------------------------------------------------------------------------- // C string terminator char // -------------------------------------------------------------------------- // #ifndef CSTRING_TERMINATOR #define CSTRING_TERMINATOR '\0' #endif // -------------------------------------------------------------------------- // filesystem special characters // -------------------------------------------------------------------------- // #define FILESYSTEM_DIRECTORY_SEPARATOR '/' #define FILESYSTEM_EXTENSION_SEPARATOR '.' #define FILESYSTEM_HOMEDIR_WILDCARD '~' #define FILESYSTEM_WORKDIR_WILDCARD '.' // -------------------------------------------------------------------------- // maximum length of a path // -------------------------------------------------------------------------- // #define MAX_PATHNAME_LENGTH 512 // -------------------------------------------------------------------------- // function fileExistAtPath(path) // -------------------------------------------------------------------------- // // check if file at path exists // int fileExistsAtPath(const char *pathname); // -------------------------------------------------------------------------- // macro fileDoesNotExistAtPath(path) // -------------------------------------------------------------------------- // // check if file at path does not exist // #define fileDoesNotExistAtPath(path) \ !(fileExistsAtPath(path)) // -------------------------------------------------------------------------- // macro isPathname(path) // -------------------------------------------------------------------------- // // check if path contains a filesystem directory separator // #define isPathname(path) \ (strchr((path), FILESYSTEM_DIRECTORY_SEPARATOR) != NULL) // -------------------------------------------------------------------------- // macro isNotPathname(path) // -------------------------------------------------------------------------- // // check if path does not contain a filesystem directory separator // #define isNotPathname(path) \ (strchr((path), FILESYSTEM_DIRECTORY_SEPARATOR) == NULL) // -------------------------------------------------------------------------- // macro isAbsolutePathname(path) // -------------------------------------------------------------------------- // // check if path starts with a filesystem directory separator // #define isAbsolutePathname(path) \ ((path != NULL) && (path[0] == FILESYSTEM_DIRECTORY_SEPARATOR)) // -------------------------------------------------------------------------- // macro isNotAbsolutePathname(path) // -------------------------------------------------------------------------- // // check if path does not start with a filesystem directory separator // #define isNotAbsolutePathname(path) \ ((path == NULL) && (path[0] != FILESYSTEM_DIRECTORY_SEPARATOR)) // -------------------------------------------------------------------------- // function copyStrFromWorkingDirectory(str) // -------------------------------------------------------------------------- // // get string with current working directory // int copyStrFromWorkingDirectory(char *str); // -------------------------------------------------------------------------- // function copyStrFromUserHomeDirectory(str) // -------------------------------------------------------------------------- // // get string with current user's home directory // int copyStrFromUserHomeDirectory(char *str); // -------------------------------------------------------------------------- // function copyStrFilenameByRemovingDirectory(str, path) // -------------------------------------------------------------------------- // // get string with filename and extension by removing directory from path // int copyStrFilenameByRemovingDirectory(char *str, const char *pathname); // -------------------------------------------------------------------------- // function copyStrFilenameByRemovingDirectoryAndFileExtension(str, path) // -------------------------------------------------------------------------- // // get string with base filename by removing directory and file extension // from path // int copyStrFilenameByRemovingDirectoryAndFileExtension(char *str, const char *pathname); // -------------------------------------------------------------------------- // function modifyFilenameByAppendingFileExtension(filename, extension) // -------------------------------------------------------------------------- // // append file extension to filename // int modifyFilenameByAppendingFileExtension(char *filename, const char *extension); // -------------------------------------------------------------------------- // function modifyFilenameByReplacingFileExtension(filename, extension) // -------------------------------------------------------------------------- // // replace file extension in filename // int modifyFilenameByReplacingFileExtension(char *filename, const char *extension); // -------------------------------------------------------------------------- // function copyStrFileExtensionByRemovingDirectoryAndFilename(str, path) // -------------------------------------------------------------------------- // // get string with file extension by removing directory and filename from // path // int copyStrFileExtensionByRemovingDirectoryAndFilename(char *str, const char *pathname); // -------------------------------------------------------------------------- // function copyStrDirectoryByRemovingFilenameAndExtension(str, path) // -------------------------------------------------------------------------- // // get string with directory by removing filename and extension from path // int copyStrDirectoryByRemovingFilenameAndExtension(char *str, const char *pathname); // -------------------------------------------------------------------------- // function modifyPathnameByAppendingFilename(pathname, filename) // -------------------------------------------------------------------------- // // append file filename to pathname // int modifyPathnameByAppendingFilename(char *pathname, const char *filename); // -------------------------------------------------------------------------- // function copyStrPathnameByExpandingTildeInPath(str, path) // -------------------------------------------------------------------------- // // get string with full pathname by expanding tilde in path // int copyStrPathnameByExpandingTildeInPath(char *str, const char *pathname); // -------------------------------------------------------------------------- // function copyStrPathnameByExpandingLeadingDotInPath(str, path) // -------------------------------------------------------------------------- // // get string with full pathname by expanding leading dot in path // int copyStrPathnameByExpandingLeadingDotInPath(char *str, const char *pathname); // -------------------------------------------------------------------------- // function copyStrPathnameByExpandingLeadingDotDotInPath(str, path) // -------------------------------------------------------------------------- // // get string with full pathname by expanding leading dotdot in path // int copyStrPathnameByExpandingLeadingDotDotInPath(char *str, const char *pathname); // -------------------------------------------------------------------------- // function copyStrPathnameByExpandingTrailingDotInPath(str, path) // -------------------------------------------------------------------------- // // get string with full pathname by expanding trailing dot in path with // filename // int copyStrPathnameByExpandingTrailingDotInPath(char *str, const char *pathname, const char *filename); // END OF FILE