Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

write function requires unistd.h on Unix, what about windows?

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?

like image 756
stockoverflow Avatar asked Dec 07 '25 10:12

stockoverflow


2 Answers

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).

like image 169
Jerry Coffin Avatar answered Dec 10 '25 10:12

Jerry Coffin


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.

like image 36
Rafe Kettler Avatar answered Dec 10 '25 10:12

Rafe Kettler