2

I've changed from a linux computer to a windows and I'm having trouble compiling my code because these two OS don't share the same header files.

Since the unistd.h is not obviously included, Visual C doesn't know what read(), write(), close(), socklen_t() and bzero()functions are. Can anyone help me with this?

I've googled this: Is there a replacement for unistd.h for Windows (Visual C)?

I have no idea how unistd.h works, nor do I know how to code my own. Can someone please link me to one?

Community
  • 1
  • 1
stockoverflow
  • 1,457
  • 5
  • 18
  • 22

2 Answers2

11

read, write and close are in <io.h>, just like they traditionally were on Unix.

Offhand, I don't know of a bzero being included on Windows at all -- if you care at all about portability, you normally want to use memset instead.

socklen_t isn't normally used on Windows -- most things that would be socklen_t on Unix use either size_t or int on Windows (socklen_t on Unix is currently another reference to the same underlying type as size_t, added in case it might be useful someday -- aka, a solution in search of a problem).

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
2

Your best bet is to use MinGW to compile the program, which includes (among other things) GCC (and its headers). Try installing that and then compiling your program and see if everything works OK.

Rafe Kettler
  • 75,757
  • 21
  • 156
  • 151
  • Sorry I'm new to Visual C... I've been compiling my code through its debug (F5), how do I change it to Visual C to use MinGW instead? – stockoverflow Apr 16 '11 at 05:43
  • @stockoverflow I'm not aware of any way to integrate Visual Studio with MinGW. You compile programs with MinGW like you would in Linux -- from the command line, generally using the same commands. – Rafe Kettler Apr 16 '11 at 05:45
  • 1
    Okay cool, command prompt is the same as the terminal on linux right? – stockoverflow Apr 16 '11 at 05:53
  • @stockoverflow not really -- some of the commands on Windows are different and many GNU/Linux programs aren't there -- but the commands for compiling with MinGW are the same as those for GCC on Linux. You shouldn't run in to any problems using the Windows command prompt. – Rafe Kettler Apr 16 '11 at 05:56