Where can I get Microsoft's POSIX subsystem for NT?
NT has a built-in protected subsystem for POSIX. It starts automatically when a POSIX application loads and stays active until shutdown. The process name is psxss.
Microsoft provides a series of POSIX utilities, including source code, in the Resource Kit. Some of the included utilities are: ar, cat, chmod, vi, ls, mv, rm, and sh.
The Resource Kit can be purchased from Microsoft, or Software Spectrum (US 800-824-3323, Canada 800-624-6224).
You can also download the utilities for free.
The Reskit is not enough to develop POSIX applications - you really need the SDK from, again, MSDN Level 2.
What are the restrictions of NT's POSIX?
The POSIX subsystem that is supplied by Microsoft with NT has several important limitations.
To quote the Resource Kit:
With this release of Windows NT, POSIX applications have no direct access to any of the facilities and features of the Win32 subsystem, such as memory mapped files, networking, graphics, or dynamic data exchange.
That one sentence says a lot! No networking means no Winsock or any other communication protocol. No graphics means that you restricted to only console-based (Command Window) applications. No memory mapped files restricts one of the methods of communicating between processes under NT. Simply stated, applications using the POSIX subsystem of NT can't do a whole lot. To do anything interesting, you need to access Microsoft's Win32 API, or at least wrap a series of Unix-like calls around the Win32 API.
Why is the POSIX subsystem so brain-damaged?
The general consensus is that Microsoft put in the POSIX subsystem in order to bid NT on U.S. government contracts where POSIX can be a requirement. The NT implementation is a strict implementation of the POSIX.1 standard and nothing more. So, the subsystem isn't so much as brain-damaged, but severely handicapped by not adding anything beyond the specification.
The unfortunate result for those wishing to port UNIX applications, is that unless the application needs no more system resources than cat, the POSIX subsystem is useless. In fact, attempting to port to the POSIX subsystem will probably be a complete waste of time as any one of several brick walls will be hit very quickly. The alternative is to start with the Win32 API and one of several porting aids listed in the next section.
How do I get vi to run?
Ah yes, one of the great secrets of the NT POSIX subsystem. See also Knowledge Base article Q108581.
First, you need to create a termcap file:
li|ansi|psx_ansi|:\ :co#80:li#25:\ :am:pt:ms:bw:\ :cl=\E[2J:cm=\E[%i%d;%dH:ce=\E[K:cd=\E[J:\ :sf=\E[S:sr=\E[T:\ :ho=\E[H:sc=\E[s:rc=\E[u:up=\E[A:d=^J:nd=\E[C:le=^H:\ :ku=\E[A:kd=\E[V:kr=\E[C:kl=\E[D:kb=^H:\ :so=\E[7m:se=\E[m:mr=\E[7m:me=\E[0m:\
Second, you need to a bunch of environment variables:
SET _POSIX_TERM=on SET TERM=ansi SET TERMCAP=location of termcap file in POSIX file format which is case-sensitive. e.g. SET TERMCAP=//D/RESKIT35/posix/termcap SET TMP=//C/TEMP
Important note: setting the TMP environment variable in POSIX style renders it incompatible with a lot of other applications, including Visual C++. So you should have a separate command window just for vi. All the other variables may be permanently set in the Control Panel\System applet.
That should be it.
Where can I found more about NT's POSIX subsystem?
In the NT 3.5 Resource Kit, Resource Guide, Chapter 17 - POSIX Compatibility.
Where can I find a version of POSIX for NT that actually works?
From Software Systems Inc. They make a product called OpenNT, which a drop-in replacement for the brain-damaged built-in POSIX subsystem.