aboutsummaryrefslogtreecommitdiffhomepage
path: root/wutil.c
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2006-02-03 01:23:56 +1000
committerGravatar axel <axel@liljencrantz.se>2006-02-03 01:23:56 +1000
commit06fd1aa9f8aa2d9705ba942055c76518fb1da1f6 (patch)
tree4a6d3e47b2b282d3b376ae31dbc02fae0a8f145f /wutil.c
parent5942a6d6c193f6d985d9f4eaada7c8113a40d1c0 (diff)
Make stack traces print absolute filenames
darcs-hash:20060202152356-ac50b-9e6ab31c03d5f49824ccca7eee3b8e62d66b0009.gz
Diffstat (limited to 'wutil.c')
-rw-r--r--wutil.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/wutil.c b/wutil.c
index b7d11593..46b88459 100644
--- a/wutil.c
+++ b/wutil.c
@@ -26,6 +26,14 @@
#define TMP_LEN_MIN 256
+#ifndef PATH_MAX
+#ifdef MAXPATHLEN
+#define PATH_MAX MAXPATHLEN
+#else
+#define PATH_MAX 4096
+#endif
+#endif
+
/**
Buffer for converting wide arguments to narrow arguments, used by
the \c wutil_wcs2str() function.
@@ -219,6 +227,61 @@ void wperror(const wchar_t *s)
fwprintf( stderr, L"%s\n", strerror( errno ) );
}
+#ifdef HAVE_REALPATH_NULL
+
+wchar_t *wrealpath(const wchar_t *pathname, wchar_t *resolved_path)
+{
+ char *tmp = wutil_wcs2str(pathname);
+ char *narrow_res = realpath( tmp, 0 );
+ wchar_t *res;
+
+ if( !narrow_res )
+ return 0;
+
+ if( resolved_path )
+ {
+ wchar_t *tmp2 = str2wcs( narrow_res );
+ wcslcpy( resolved_path, tmp2, PATH_MAX );
+ free( tmp2 );
+ res = resolved_path;
+ }
+ else
+ {
+ res = str2wcs( narrow_res );
+ }
+
+ free( narrow_res );
+
+ return res;
+}
+
+#else
+
+wchar_t *wrealpath(const wchar_t *pathname, wchar_t *resolved_path)
+{
+ char *tmp =wutil_wcs2str(name);
+ char narrow[PATH_MAX];
+ char *narrow_res = realpath( tmp, narrow );
+ wchar_t *res;
+
+ if( !narrow_res )
+ return 0;
+
+ if( resolved_path )
+ {
+ wchar_t *tmp2 = str2wcs( narrow_res );
+ wcslcpy( resolved_path, tmp2, PATH_MAX );
+ free( tmp2 );
+ res = resolved_path;
+ }
+ else
+ {
+ res = str2wcs( narrow_res );
+ }
+ return res;
+}
+
+#endif
#if !HAVE_FWPRINTF