Windows <sys/file.h> equivalent

谁都会走 提交于 2019-12-22 06:37:01

问题


Is there a Win32 equivalent to the linux header file? I'm working on a Linux to Windows port (and my first time doing so) and it's failing on this file.


回答1:


When writing WIN32API apps you usually #include <windows.h> - that includes most of the Windows API in your application. If you need to cut down on some of those includes, #define WIN32_LEAN_AND_MEAN will wipe out some of the more obscure things from the Windows libraries.

What functions are you trying to convert? It'll probably be a case of using a different function on WIN32; it is very different to Linux/Unix/POSIX.

Example: the ReadFile() function is roughly equivalent to read() in terms of general idea, but the calling signatures are very different. ReadFile()'s MSDN entry says:

Header: WinBase.h (include Windows.h)




回答2:


If you are porting to windows, it would be far easier to stick to cross platform standards, than diving straight into a native windows API port (CreateFile etc.).

I don't know what functionality is in <sys/file.h>, it looks like its part of the POSIX standard header files, but I can't find a reference to it in the posix sources.

There are a few build environments that you can use to port posix applications to Windows.

  • If your application sticks to the C standard library for things like file IO, Dev Studio should support most of that natively. <stdio.h> for example has things like fopen.
  • MinGW provides a set of tools, but uses the microsoft c-runtime, so things like pthreads should be missing.
  • Cygwin is a far more conformant POSIX build environment.
  • SUA is Microsofts own offering.



回答3:


For the benefit of posterity, <sys/file.h> is the BSD version of low-level file I/O routines. Depending upon your compiler installation and build environment, you'll probably want <fcntl.h> instead. Most of the usual I/O routines are in <stdio.h>, even setvbuf() which is pretty low-level control. You'll want <windows.h> or <conio.h> if you want I/O routines/settings that don't normally exist under Linux (or the other *NICES).



来源:https://stackoverflow.com/questions/2537960/windows-sys-file-h-equivalent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!