Unbuffered I/O using MicroSoft C 3.0

bet at ecsvax.UUCP bet at ecsvax.UUCP
Thu Jan 29 10:25:09 AEST 1987


While setbuf will still be needed to get unbuffered I/O, there is a
wondrously simple way to ensure that I/O doesn't get redirected without
mucking about with DOS interrupts! Like so:

	FILE *fopen(), *console;

	console = fopen("\\dev\\con", "r");

The '\' characters are doubled because '\' is the quoting character in C
strings; you can simplify the above to the more obvious:

	FILE *fopen(), *console;

	console = fopen("con", "r");

(or "con:", or whatever floats your boat) if you are guaranteed that
your program will never be run on a system using the undocumented DOS
AVAILDEV function to hide devices.

-Bennett

P.S. AVAILDEV:

Issue DOS function call INT 21H with AH=37H to access SWITCHAR and
AVAILDEV:

	AL=0	read SWITCHAR value into DL
	AL=1	set SWITCHAR from DL
	AL=2	read AVAILDEV into DL
	AL=3	set AVAILDEV from DL

The SWITCHAR is the character used for "switches" in DOS command
arguments (defaults to '/', as in "DIR /P"). '-' is popular to make a
system look more like UNIX; if the SWITCHAR is anything other than '/',
then '/' may be used instead of '\' for pathnames (even more like
UNIX!). AVAILDEV=0 means than devices must be referenced in an imaginary
subdirectory "\dev" (shades of UNIX's /dev/*); a filename "prn.dat" can
be created on disk and manipulated like any other. If AVAILDEV != 0 then
device names are recognized anywhere (this is the default): "prn.dat"
is synonymous with "prn:".

NOTE: These functions are undocumented, whicn means they are
unsupported, which means they are liable to go away whenever Microsoft
is feeling frisky. Use at your own risk! However, PLEASE program around
them to make life nicer for the daring souls who take the risk.

-Bennett
-- 
Bennett Todd -- Duke Computation Center, Durham, NC 27706-7756; (919) 684-3695
UUCP: ...{decvax,seismo,philabs,ihnp4,akgua}!mcnc!ecsvax!duccpc!bet
BITNET: DBTODD at TUCC.BITNET -or- DBTODD at TUCCVM.BITNET -or- bet at ECSVAX.BITNET
terrorist, cryptography, DES, drugs, cipher, secret, decode, NSA, CIA, NRO.



More information about the Comp.lang.c mailing list