# HG changeset patch # User Sascha Wilde # Date 1395678186 -3600 # Node ID 306e4db1176134858b64b421157fbf1d3e0506f8 # Parent 27ebd96798c4d490e679fcb7737513449cab6f88 Added portable path name handling functions. Windows implementation missing. diff -r 27ebd96798c4 -r 306e4db11761 common/CMakeLists.txt --- a/common/CMakeLists.txt Mon Mar 24 16:25:32 2014 +0100 +++ b/common/CMakeLists.txt Mon Mar 24 17:23:06 2014 +0100 @@ -1,6 +1,7 @@ set (m13_common_src listutil.c strhelp.c + portpath.c ) add_library(m13_common STATIC ${m13_common_src}) diff -r 27ebd96798c4 -r 306e4db11761 common/portpath.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/portpath.c Mon Mar 24 17:23:06 2014 +0100 @@ -0,0 +1,30 @@ +#include "portpath.h" + +#include +#include +#include +#include + + +char * +port_dirname(char *path) +{ +#ifndef _WIN32 + return dirname(path); +#else + fprintf(stderr, "Windows Suport missing!"); + abort(); +#endif + +} + +char * +port_realpath(char *path) +{ +#ifndef _WIN32 + return realpath(path, NULL); +#else + fprintf(stderr, "Windows Suport missing!"); + abort(); +#endif +} diff -r 27ebd96798c4 -r 306e4db11761 common/portpath.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/portpath.h Mon Mar 24 17:23:06 2014 +0100 @@ -0,0 +1,41 @@ +#ifndef PORTPATH_H +#define PORTPATH_H + +/** + * @file portpath.h + * @brief Platform independent functions for file and path handling. + * @details portpath contains functions to handle file and path names + * in a platform independent way. The code unsing this functions + * should be protable between GNU/Linux and Windows32 systems. + */ + +/** + * @brief portable version of dirname + * @details return the directory component of the given path. + * The argument path may be altered by the function. + * @param[inout] path the pathname + * @returns a pointer to the string containing the directory component + */ +char *port_dirname(char *path); + + +/** + * @brief portable version of dirname + * @details return the directory component of the given path. + * The argument path may be altered by the function. + * @param[inout] path the pathname + * @returns a pointer to the string containing the directory component + */ +char *port_dirname(char *path); + +/** + * @brief portable version of realpath + * @details return the expanded absolute pathname for the given path. + * The buffer for the resolved path is allocated by this function and + * should be freed by the caller. + * @param[in] path the original pathname + * @returns a pointer to the resolved path or NULL on error + */ +char *port_realpath(char *path); + +#endif