Re: [RFC] Reenable compilation with cygwin 1.5 versions

Christopher Faylor
2010-03-03T20:30:23Z

On Wed, Mar 03, 2010 at 05:54:43PM +0100, Pierre Muller wrote:
>Index: remote-fileio.c
>===================================================================
>RCS file: /cvs/src/src/gdb/remote-fileio.c,v
>retrieving revision 1.34
>diff -u -p -r1.34 remote-fileio.c
>--- remote-fileio.c 1 Mar 2010 09:09:24 -0000 1.34
>+++ remote-fileio.c 3 Mar 2010 16:11:15 -0000
>@@ -35,6 +35,11 @@
> #include <sys/time.h>
> #ifdef __CYGWIN__
> #include <sys/cygwin.h> /* For
>cygwin_conv_to_full_posix_path. */
>+#include <cygwin/version.h>
>+#if
>CYGWIN_VERSION_DLL_MAKE_COMBINED(CYGWIN_VERSION_API_MAJOR,CYGWIN_VERSION_API
>_MINOR) < 181
>+#define __USE_OLD_CYGWIN_API_
>+#endif
>+
> #endif
> #include <signal.h>
>
>@@ -1021,14 +1026,24 @@ remote_fileio_func_rename (char *buf)
> errno = EISDIR;
> else
> {
>+#ifndef __USE_OLD_CYGWIN_API_
> char oldfullpath[PATH_MAX];
> char newfullpath[PATH_MAX];
>+#else /* __USE_OLD_CYGWIN_API_ */
>+ char oldfullpath[PATH_MAX + 1];
>+ char newfullpath[PATH_MAX + 1];
>+#endif /* __USE_OLD_CYGWIN_API_ */
> int len;
>
>+#ifndef __USE_OLD_CYGWIN_API_
> cygwin_conv_path (CCP_WIN_A_TO_POSIX, oldpath,
>oldfullpath,
> PATH_MAX);
> cygwin_conv_path (CCP_WIN_A_TO_POSIX, newpath,
>newfullpath,
> PATH_MAX);
>+#else /* __USE_OLD_CYGWIN_API_ */
>+ cygwin_conv_to_full_posix_path (oldpath, oldfullpath);
>+ cygwin_conv_to_full_posix_path (newpath, newfullpath);
>+#endif /* __USE_OLD_CYGWIN_API_ */
> len = strlen (oldfullpath);
> if (newfullpath[len] == '/'
> && !strncmp (oldfullpath, newfullpath, len))

I think it would be cleaner to define a cygwin_conv_path at the top of the file
based on cygwin_conv_to_full_posix_path. Then no __USE_OLD_CYGWIN_API_ would
be necessary (given the understanding that the PATH_MAX changes aren't needed).

>Index: windows-nat.c
>===================================================================
>RCS file: /cvs/src/src/gdb/windows-nat.c,v
>retrieving revision 1.204
>diff -u -p -r1.204 windows-nat.c
>--- windows-nat.c 1 Mar 2010 09:09:24 -0000 1.204
>+++ windows-nat.c 3 Mar 2010 16:11:15 -0000
>@@ -41,6 +41,12 @@
> #include <psapi.h>
> #ifdef __CYGWIN__
> #include <sys/cygwin.h>
>+#include <cygwin/version.h>
>+#if
>CYGWIN_VERSION_DLL_MAKE_COMBINED(CYGWIN_VERSION_API_MAJOR,CYGWIN_VERSION_API
>_MINOR) < 181
>+#define __USE_OLD_CYGWIN_API_
>+#else
>+#define __USE_NEW_CYGWIN_API_
>+#endif
> #endif
> #include <signal.h>
>
>@@ -71,11 +77,11 @@
> #define DebugBreakProcess dyn_DebugBreakProcess
> #define DebugSetProcessKillOnExit dyn_DebugSetProcessKillOnExit
> #define EnumProcessModules dyn_EnumProcessModules
>-#ifndef __CYGWIN__
>+#ifndef __USE_NEW_CYGWIN_API_
> #define GetModuleFileNameExA dyn_GetModuleFileNameExA
>-#else
>+#else /* __USE_NEW_CYGWIN_API_ */
> #define GetModuleFileNameExW dyn_GetModuleFileNameExW
>-#endif
>+#endif /* __USE_NEW_CYGWIN_API_ */
> #define GetModuleInformation dyn_GetModuleInformation
> #define LookupPrivilegeValueA dyn_LookupPrivilegeValueA
> #define OpenProcessToken dyn_OpenProcessToken
>@@ -87,13 +93,13 @@ static BOOL WINAPI (*DebugBreakProcess)
> static BOOL WINAPI (*DebugSetProcessKillOnExit) (BOOL);
> static BOOL WINAPI (*EnumProcessModules) (HANDLE, HMODULE *, DWORD,
> LPDWORD);
>-#ifndef __CYGWIN__
>+#ifndef __USE_NEW_CYGWIN_API_
> static DWORD WINAPI (*GetModuleFileNameExA) (HANDLE, HMODULE, LPSTR,
> DWORD);
>-#else
>+#else /* __USE_NEW_CYGWIN_API_ */
> static DWORD WINAPI (*GetModuleFileNameExW) (HANDLE, HMODULE, LPWSTR,
> DWORD);
>-#endif
>+#endif /* __USE_NEW_CYGWIN_API_ */
> static BOOL WINAPI (*GetModuleInformation) (HANDLE, HMODULE, LPMODULEINFO,
> DWORD);
> static BOOL WINAPI (*LookupPrivilegeValueA)(LPCSTR, LPCSTR, PLUID);

Here also, it seems like just defining and using a GetModulesFileNameEx,
etc. and deciding whether to do "A" or "W" in a macro would be much
cleaner. You probably still need to make decisions about using wide
characters but the test should be on something like "USE_WIDE_CHARS"
rather than "__USE_NEW_CYGWIN_API" since, the use of wide characters
doesn't really have anything to do with the new Cygwin API.

cgf