aheinecke@404: /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik aheinecke@404: * Software engineering by Intevation GmbH aheinecke@404: * aheinecke@404: * This file is Free Software under the GNU GPL (v>=2) aheinecke@404: * and comes with ABSOLUTELY NO WARRANTY! aheinecke@404: * See LICENSE.txt for details. aheinecke@404: */ wilde@146: #ifndef PORTPATH_H wilde@146: #define PORTPATH_H wilde@146: wilde@168: #include andre@1157: #include wilde@168: wilde@146: /** wilde@146: * @file portpath.h wilde@146: * @brief Platform independent functions for file and path handling. wilde@146: * @details portpath contains functions to handle file and path names wilde@146: * in a platform independent way. The code unsing this functions wilde@146: * should be protable between GNU/Linux and Windows32 systems. wilde@146: */ wilde@146: wilde@146: /** wilde@146: * @brief portable version of dirname wilde@146: * @details return the directory component of the given path. wilde@146: * The argument path may be altered by the function. wilde@146: * @param[inout] path the pathname wilde@146: * @returns a pointer to the string containing the directory component wilde@146: */ wilde@146: char *port_dirname(char *path); wilde@146: wilde@146: /** wilde@146: * @brief portable version of realpath wilde@146: * @details return the expanded absolute pathname for the given path. wilde@146: * The buffer for the resolved path is allocated by this function and wilde@146: * should be freed by the caller. wilde@146: * @param[in] path the original pathname wilde@146: * @returns a pointer to the resolved path or NULL on error wilde@146: */ andre@975: char *port_realpath(const char *path); wilde@146: wilde@168: /** wilde@168: * @brief test if a file exists wilde@168: * @details uses a platform specific stat call to test if the given wilde@168: * file exists. wilde@168: * @param[in] path the path to the file wilde@168: * @returns true if the file exists and false otherwise wilde@168: */ wilde@168: bool port_fileexits(char *path); wilde@168: wilde@176: /** wilde@176: * @brief test if a file is a directory wilde@176: * @details uses a platform specific stat call to test if the given wilde@176: * file is an directory. wilde@176: * @param[in] path the path to the file wilde@176: * @returns true if the file is an directory and false otherwise wilde@176: */ andre@984: bool port_isdir(const char *path); wilde@176: andre@975: /** andre@975: * @brief create a directory andre@975: * @details uses a platform specific mkdir / access rights setup andre@975: * to create a directory that is world readable and andre@975: * writable by the current user / group andre@975: * @param[in] path the path to the directory andre@1070: * @param[in] propagate_acl weather or not objects should inherit andre@1070: * the ACL of this directory. Only has an effect on Windows. andre@975: * @returns true if the directory was created andre@975: */ andre@1070: bool port_mkdir(const char *path, bool propagate_acl); andre@975: andre@984: /** andre@984: * @brief create a directory and its parent directores andre@1070: * andre@1070: * On Windows the last directory will propagate it's ACL andre@1070: * to objects and subdirectories. The parent directories andre@1070: * will not. andre@1070: * andre@1070: * @param[in] propagate_acl weather or not the andre@1070: * last created directory should propagate it's acl. andre@1070: * Only has an effect on Windows. andre@984: * @param[in] path the path to the directory andre@984: * @returns true if the directory was created andre@984: */ andre@1070: bool port_mkdir_p(const char *path, bool propagate_acl); andre@984: andre@1157: /** andre@1157: * @brief Open a file in read binary mode andre@1157: * andre@1157: * @param[in] path UTF-8 (or local 8 bit encoding) andre@1157: * encoded filename andre@1157: * @param[in] exclusive weather or not to open the file with andre@1157: * a denywr lock. Ignored under linux. andre@1157: * @returns the same as fopen. andre@1157: */ andre@1157: FILE* port_fopen_rb(const char *path, bool exclusive); andre@1157: wilde@146: #endif