Revision: 1052
http://cegcc.svn.sourceforge.net/cegcc/?rev=1052&view=rev
Author: pedroalves
Date: 2007-09-02 15:51:09 -0700 (Sun, 02 Sep 2007)
Log Message:
-----------
* cwd.h (libcwd_fixpath): Declare.
* cwd.c (XCEGetCurrentDirectoryA): Delay XCEGetCurrentDirectoryW
call to after checking for valid buffer.
(libcwd_fixpath): New.
Modified Paths:
--------------
trunk/cegcc/tools/libcwd/ChangeLog
trunk/cegcc/tools/libcwd/cwd.c
trunk/cegcc/tools/libcwd/cwd.h
Modified: trunk/cegcc/tools/libcwd/ChangeLog
===================================================================
--- trunk/cegcc/tools/libcwd/ChangeLog 2007-09-02 17:59:12 UTC (rev 1051)
+++ trunk/cegcc/tools/libcwd/ChangeLog 2007-09-02 22:51:09 UTC (rev 1052)
@@ -1,3 +1,10 @@
+2007-09-02 Pedro Alves <ped...@po...>
+
+ * cwd.h (libcwd_fixpath): Declare.
+ * cwd.c (XCEGetCurrentDirectoryA): Delay XCEGetCurrentDirectoryW
+ call to after checking for valid buffer.
+ (libcwd_fixpath): New.
+
2007-06-25 Pedro Alves <ped...@po...>
Initial import.
Modified: trunk/cegcc/tools/libcwd/cwd.c
===================================================================
--- trunk/cegcc/tools/libcwd/cwd.c 2007-09-02 17:59:12 UTC (rev 1051)
+++ trunk/cegcc/tools/libcwd/cwd.c 2007-09-02 22:51:09 UTC (rev 1052)
@@ -169,9 +169,9 @@
DWORD dwLen;
wchar_t wbuf[MAX_PATH+1];
- dwLen = XCEGetCurrentDirectoryW (dwSize, wbuf);
if (dwSize == 0 && buf == 0)
return dwSize;
+ dwLen = XCEGetCurrentDirectoryW (dwSize, wbuf);
WideCharToMultiByte (CP_ACP, 0, wbuf, -1,
buf, MIN(dwLen, dwSize), NULL, NULL);
buf[MIN(dwLen, dwSize)] = 0;
@@ -318,3 +318,46 @@
{
return _getcwd (buf, size);
}
+
+char*
+libcwd_fixpath (char* out, const char *in)
+{
+ wchar_t wout[MAX_PATH];
+ wchar_t win[MAX_PATH];
+
+ mbstowcs (win, in, MAX_PATH);
+// XCEFixPathW (win, wout);
+ const wchar_t *wpathin = win;
+ wchar_t *wpathout = wout;
+ {
+ wchar_t wdir[MAX_PATH+1];
+ wchar_t *p;
+
+ wpathout[0] = 0;
+
+ if(wpathin[0] != '\\' && wpathin[0] != '/')
+ {
+ XCEGetCurrentDirectoryW (sizeof(wdir), wdir);
+ wcscat (wpathout, wdir);
+ append_slash_if_needed (wpathout);
+ }
+
+ wcscat (wpathout, wpathin);
+
+ for(p = wpathout; *p; p++)
+ {
+ if(*p == '/')
+ *p = '\\';
+ }
+
+ /* Don't allow slash at end of directory name... */
+ if(p[-1] == '\\' && p != wpathout + 1)
+ p[-1] = 0;
+
+ /* Now remove . and .. */
+ XCECanonicalizePathW (wpathout);
+ }
+
+ wcstombs (out, wout, MAX_PATH);
+ return out;
+}
Modified: trunk/cegcc/tools/libcwd/cwd.h
===================================================================
--- trunk/cegcc/tools/libcwd/cwd.h 2007-09-02 17:59:12 UTC (rev 1051)
+++ trunk/cegcc/tools/libcwd/cwd.h 2007-09-02 22:51:09 UTC (rev 1052)
@@ -12,6 +12,8 @@
extern int chdir (const char *path);
extern int _chdir (const char *path);
+extern char* libcwd_fixpath (char* out, const char *in);
+
#ifdef __cplusplus
}
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|