CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2001
    Posts
    1,029

    errno difference between windows and linux?

    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!

  2. #2
    Join Date
    Mar 2001
    Posts
    2,529

    Re: errno difference between windows and linux?

    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.
    Code:
    #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
    Last edited by ahoodin; January 8th, 2009 at 08:59 AM.
    ahoodin
    To keep the plot moving, that's why.

  3. #3
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: errno difference between windows and linux?

    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...)
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured