changeset 146:306e4db11761

Added portable path name handling functions. Windows implementation missing.
author Sascha Wilde <wilde@intevation.de>
date Mon, 24 Mar 2014 17:23:06 +0100
parents 27ebd96798c4
children fc9af77b06b9
files common/CMakeLists.txt common/portpath.c common/portpath.h
diffstat 3 files changed, 72 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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})
--- /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 <libgen.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+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
+}
--- /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

http://wald.intevation.org/projects/trustbridge/