在 Unix 上 write 函数需要 unistd.h,那么 windows 呢?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5684679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 16:39:43  来源:igfitidea点击:

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

cwindowsvisual-studioposixunistd.h

提问by stockoverflow

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.

我已经从 linux 计算机更改为 windows 并且我在编译代码时遇到了麻烦,因为这两个操作系统不共享相同的头文件。

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?

由于unistd.h中不包含明显,视觉C不知道是什么read()write()close()socklen_t()bzero()功能。谁能帮我这个?

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

我在谷歌上搜索过这个:Windows (Visual C) 是否有 unistd.h 的替代品?

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

我不知道 unistd.h 是如何工作的,也不知道如何编写自己的代码。有人可以将我链接到一个吗?

采纳答案by Rafe Kettler

Your best bet is to use MinGWto 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.

最好的办法是使用MinGW编译程序,其中包括(除其他外)GCC(及其头文件)。尝试安装它,然后编译您的程序,看看是否一切正常。

回答by Jerry Coffin

read, writeand closeare in <io.h>, just like they traditionally were on Unix.

read,writeclose在 中<io.h>,就像它们传统上在 Unix 上一样。

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

顺便说一句,我根本不知道bzeroWindows 中是否包含一个工具——如果您完全关心可移植性,您通常想memset改用它。

socklen_tisn't normally used on Windows -- most things that would be socklen_ton Unix use either size_tor inton Windows (socklen_ton 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).

socklen_t通常不使用Windows上-大多数事情,这将是socklen_t在Unix兼用size_tint在Windows(socklen_t在Unix上是目前的另一个引用相同的基础类型size_t,在增加的情况下它可能是有益的一天-又名,在溶液中搜索问题)。