Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!necntc!ames!amdahl!bnrmtv!connery From: connery@bnrmtv.UUCP (Glenn Connery) Newsgroups: comp.sys.ibm.pc,comp.lang.c Subject: Re: Determining if a file is a device Message-ID: <2771@bnrmtv.UUCP> Date: Tue, 6-Oct-87 12:31:13 EDT Article-I.D.: bnrmtv.2771 Posted: Tue Oct 6 12:31:13 1987 Date-Received: Sat, 10-Oct-87 07:19:37 EDT References: <1738@killer.UUCP> Organization: Bell Northern Research, Mtn. View, CA Lines: 37 Summary: Use IOCTL on the handle Xref: mnetor comp.sys.ibm.pc:8759 comp.lang.c:4751 In article <1738@killer.UUCP>, wnp@killer.UUCP (Wolf Paul) writes: > In trying to implement a function which emulates the UNIX stat(2) > system call I have run into a problem: > > How can I determine whether a filename passed to a C function > is a regular file or the name of a device? > The DOS IOCTL call can be used to determine if a handle corresponds to a device or a file. Don't know how to determine this info without openning the file I'm afraid (aside from something really gory). For example the following fragment will determine if the stdout handle is attached to a file or a device... #include #include /* IsConsole - determine if stdout is connected to console or not returns TRUE if stdout is the console, FALSE if not */ int IsConsole() { union REGS r; r.x.ax = 0x4400; r.x.bx = 1; intdos(&r, &r); return((r.x.dx & 1) && (r.x.dx & 0x80)); /* isdev && iscin */ } -- Glenn Connery, Bell Northern Research, Mountain View, CA {hplabs,amdahl,3comvax}!bnrmtv!connery