This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch/libiberty] Add w32 version of lrealpath
- From: Danny Smith <danny_r_smith_2001 at yahoo dot co dot nz>
- To: gcc-patches at gcc dot gnu dot org
- Cc: dj at redhat dot com
- Date: Sat, 22 Feb 2003 10:54:59 +1100 (EST)
- Subject: [Patch/libiberty] Add w32 version of lrealpath
Hello.
Mingw doesn't have have realpath function, but since it doesn't have
symlinks, the W32api function GetFullPathName or the msvcrt.dll
function _fullpath would do the job of canonicalizing a relative
pathname to an absolute path.
This patch provides a mingw version of lrealpath, using the W32api
function which is available to all win32 targets.
I have guarded the new code with ifdef _WIN32.
If this is unacceptable, would a configure test for HAVE_W32API be
better?
Tested on GCC trunk(20030220)/i386-pc-mingw32
Danny
2003-02-21 Danny Smith <dannysmith at users dot sourceforge dot net>
* lrealpath.c (lrealpath): Add a W32api version.
Index: lrealpath.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/lrealpath.c,v
retrieving revision 1.1
diff -c -3 -p -r1.1 lrealpath.c
*** lrealpath.c 20 Feb 2003 22:11:13 -0000 1.1
--- lrealpath.c 21 Feb 2003 23:12:46 -0000
*************** extern char *canonicalize_file_name (con
*** 64,69 ****
--- 64,74 ----
# define REALPATH_LIMIT MAXPATHLEN
# endif
# endif
+ #else
+ # if defined (_WIN32)
+ # define WIN32_LEAN_AND_MEAN
+ # include <windows.h> /* for GetFullPathName */
+ # endif
#endif
char *
*************** lrealpath (filename)
*** 120,125 ****
--- 125,144 ----
free (buf);
return ret;
}
+ }
+ #endif
+
+ /* The W32API method. If we don't have realpath, we assume we don't
+ have symlinks and just canonicalize to a Windows absolute path. */
+ #if defined (_WIN32)
+ {
+ char buf[MAX_PATH];
+ char* finalpart;
+ DWORD len = GetFullPathName (filename, MAX_PATH, buf, &finalpart);
+ if (len == 0 || len > MAX_PATH-1) /* failure */
+ return strdup (filename);
+ else
+ return strdup (buf);
}
#endif
http://mobile.yahoo.com.au - Yahoo! Mobile
- Exchange IMs with Messenger friends on your Telstra or Vodafone mobile phone.