Simon Josefsson wrote: > 3) Is there any chance that the #define gethostname rpl_gethostname and > replacement prototype of gethostname in gnulib's unistd.h will cause > problems? Consider that gethostname in winsock2.h is declared with > PASCAL calling conventions, so the prototype is not the same as the one > that gnulib uses. That may cause problems in some weird situations, but > I can't see them right now. The self test works fine.
I was invisioning a situation where a package that is already Winsock-aware (i.e. does its own WSAStartup) erroniously adds the gethostname module. Then the replacement would be pulled in, resulting in a Startup+Cleanup when it's not desired, which would potentially trash any open socket operations the app might have at that point. However, the MSDN page does say that Startup/Cleanup are reference counted and the teardown is only done in the case where the count goes to 0. So as long as the replacement gethostname always does them in pairs this should be fine. > 4) Is calling WSAStartup/WSACleanup in each gnulib replacement module a > good idea? I could easily argue that it is simpler for everyone if > gnulib simply say that if you care about Windows portability, you need > to call WSAStartup+WSACleanup yourself. The gnulib module 'sockets' > could be used for this, and then the 'gethostname' module may not need > to depend directly on the 'sockets' module. I think neglecting to WSAStartup is one of the most common mistakes when porting socket applications to Win32. Couldn't there be a gnulib module that perhaps wraps main() to first call WSAStartup() and atexit(WSACleanup()) so that portable sockets programs don't have to see any of it? (I'm not even sure if the atexit is really necessary -- MSDN does say "There must be a call to WSACleanup for each successful call to WSAStartup" but that is in the context of explaining the reference count. I'm nearly certain that the required cleanup is also done when the process terminates normally.) > 5) Does this result in the right thing on cygwin? I suppose it should > detect that gethostname is present and not do anything beyond that. It looks fine here. WINDOWS_SOCKETS is not defined and the replacement is not used. Brian