delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/05/26/23:24:59

From: wozzle!alane AT imageek DOT york DOT cuny DOT edu
Subject: Re: Library problems
To: imageek!cyfhsite!chris
Date: Thu, 26 May 1994 19:46:38 -0400 (EDT)
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu

> In a previous message, Eric Backus wrote:
> > 
> > One way to make fstat() and stat() consistant would be to have fstat()
> > call stat().  There must be some way to ask DOS for the pathname
> > associated with the file pointer that fstat() gets, but I'm not a DOS
> > expert so I don't know how to do that.
> 
> There's no easy documented way to do this. The undocumented way to do this
> is to look up the file handle in the undocumented DOS system file table.
> That'll yield only the filename (without path prefix). Getting a complete

Here's how to do it in real mode. Protected mode is left as an exercise
for the reader :)

/*
    truename.c -- calls the DOS truename function to get a
    fully qualified pathname from a partial pathname; this
    takes into account any JOINed or SUBSTed drives, and any
    network redirection

    11/29/93 alane AT wozzle DOT linet DOT org
*/

#include <string.h>
#include <dos.h>
#include <dir.h>

#define F86Carry 0x0001

int truename(char far *pszOrig, char far *pszTrue)
{
    asm {
        push ds;
        push es;
    }

    _DI=FP_OFF(pszTrue);
    _SI=FP_OFF(pszOrig);
    _ES=FP_SEG(pszTrue);
    _DS=FP_SEG(pszOrig);
    _AH=0x60;

    geninterrupt(0x21);

    asm {
        pop es;
        pop ds;
    }

    return (_FLAGS & F86Carry) ? _AX : 0;
}

The interface was found in 'Undocumented DOS'. That is an
indispensible book for the DOS hacker.

To see how this works, just type 'truename somefile' at any DOS prompt
(where DOS is version 5.x or higher). It's built into command.com,
although that isn't documented either <sigh>.

-- 
J. Alan Eldridge (alane AT wozzle DOT linet DOT org)


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019