Click to See Complete Forum and Search --> : errno difference between windows and linux?
lab1
January 8th, 2009, 06:54 AM
Hello all,
If I am trying to write a cross-platform (windows/Linux) tcp package.. what is the best way to handle errno? Are the enums different for each OS? Would passing back strerror(errno) be sufficient?
Thanks!
ahoodin
January 8th, 2009, 07:53 AM
Winsock uses WSAGetLastError() while UNIX and Linux and Free BSD all use errno.
if you are going to make a single portable source code, you can use the preprocessor to cover the gap.
#ifdef WIN32//defined by wizard
//put your windows specific code here such as
//dealing with error conditions and loading the winsock dll.
#elif defined(FREEBSD) //this is your custom define
//put your NIX code h for dealing with error codes etc
#elif defined (YADAYADA)(//whatever else you have to define
//whatever you have to do.
#endif
TheCPUWizard
January 8th, 2009, 08:03 AM
To the best of my knowledge there is no established standard that mandates al of the values be identical.
Since I prefer to play it safe, I always have a platform specific class which translates the system error number into a enum that I control. (Also I generally translate most of them into exceptions which are then thrown...)
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.