开发者

Windows <sys/file.h> equivalent

Is there a Win32 equivalent to the linux header file? I'm working on a Linux t开发者_StackOverflow中文版o Windows port (and my first time doing so) and it's failing on this file.


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)


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜