[freetds] Using freetds in Windows

Frediano Ziglio freddy77 at gmail.com
Tue Jan 12 04:10:26 EST 2010

2010/1/12 James K. Lowden <jklowden at freetds.org>:
> Frediano Ziglio wrote:
>> Perhaps would be better to translate C
>> errors into Windows system errors and use FormatMessage for windows and
>> strerror for Unix?
> Winsock errors cannot be formatted with FormatMessage.  That's why we have
> tds_prwsaerror().

?? I execute attached format_message.c and give:

NO_ERROR -> The operation completed successfully.
WSAEINTR -> A blocking operation was interrupted by a call to
WSAEBADF -> The file handle supplied is not valid.
WSAEACCES -> An attempt was made to access a socket in a way forbidden
by its access permissions.
WSAEFAULT -> The system detected an invalid pointer address in
attempting to use a pointer argument in a call.

without any errors in both Windows Xp and Windows 2000. I don't have a
NT4 machine and I don't care about too old windows versions. This
should work on all Win32/Win64 platforms so at least somebody have
windows 16 the code is ok.

>> we always use strerror, windows or not.
> It matters more to you than to me.  :-)
> In the db-lib code we don't need to support multithreading.  I don't know
> how to use errno portably in multithreaded code.  I would like to believe
> that in any environment in which errno is in thread-local storage,
> strerror(3) would be thread-safe.

errno is currently quite portable and thread-safe, strerror not, there
is a strerror_r to solve the problem.

> I encountered a bug today in replacements/strtok_r().  It doesn't treat
> consecutive tokens as one, so at the end of the port 1434 response (two
> semicolons), it returns a zero-length string instead of NULL.  It made me
> wish we'd single-threaded the code instead of replacing it with something
> that almost works.

I'll fix it.

>> I think that a developer
>> have to use perl even on windows or manually copy file from distribution
>> while users will use distribution which came with proper file.
> Agreed.
>> Why not adding .sln/.vcproj and Nmakefile to distribution ??
> Laziness.  Good idea, though.
>> It's that macro is defined in replacements.h and tds_sysdep_private.h so
>> I got a warning about redefinition. I build defncopy as cross compile
>> using FreeTDS library (not MS one).
> Understood.  It's good you use Mingw and I use VS 2005.  If we get it to
> compile both ways, we're doing something right.

This raise a coherency question: what should we put into
tds_sysdep_private.h and in replacements.h??
The difference between tds_sysdep_private and tds_sysdep_public is
clear, tds_sysdep_public have to be distributed in order to compile
cklient programs while tds_sysdep_private is used to make internal
code portable so it's ok to use in unittests or internal application
(like defncopy). replacements.h was added to provide definitions for
functions replaced or not available so it define functions/macro to
allow the use of undefined functions, even system dependent one.
Perhaps tds_sysdep_private should include replacements? No, I think
not, replacements it's also used for our small replacements functions
definitions so I would suggest this rule: if we have some function
defined in replacement library define in replacements.h else define in
tds_sysdep includes (mostly tds_sysdep_private). So strcasecmp (which
doesn't have function defined in replacement library) should go to
tds_sysdep_private. Do you agree?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: format_message.c
Type: application/octet-stream
Size: 2430 bytes
Desc: not available
Url : http://lists.ibiblio.org/pipermail/freetds/attachments/20100112/8e855a57/attachment.obj 

More information about the FreeTDS mailing list