home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / cprog / actlib12.zip / TOOLS.ZIP / TRUENAME.C < prev    next >
C/C++ Source or Header  |  1993-02-25  |  1KB  |  54 lines

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)  */
  2.  
  3. #include "tools.h"
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <dos.h>
  7.  
  8.  
  9. /***
  10.  *
  11.  *  Function   :    truename
  12.  *
  13.  *  Topics     :    Transforms a filename into a full reduced filename.
  14.  *                  Resolves all SUBST's, JOIN's, network names,...
  15.  *
  16.  *  Parameters  :  in/out   char *filename    input/reduced filename
  17.  *
  18.  *  Warning    :    - Valid only for DOS >= 2.0
  19.  *                  - Trailing '\' is not removed
  20.  *
  21.  *  Return code:    0      OK
  22.  *                  2  Invalid syntax
  23.  *                  3  Invalid drive or path
  24.  ***/
  25.  
  26. int truename( char *filename )
  27.  
  28. { int status;
  29.   union REGS regs;
  30.   struct SREGS sregs;
  31.   char *ptr;
  32.  
  33.   for ( ptr = filename; *ptr; ptr ++ ) if ( *ptr == '/' ) *ptr = '\\';
  34.  
  35.         /*
  36.         DOS Interrupt 60H
  37.         Input:  DS:SI = pointer to filename
  38.                 ES:DI = pointer to hold 128 byte canonicalized filename
  39.         Output: carry flag set if error and AX = error code
  40.                 if no error, ES:DI is filled in
  41.         */
  42.  
  43.   sregs.ds  = FP_SEG( filename );
  44.   regs.x.si = FP_OFF( filename );
  45.   sregs.es  = FP_SEG( filename );
  46.   regs.x.di = FP_OFF( filename );
  47.   regs.h.ah = 0x60;
  48.   status = intdosx( ®s, ®s, &sregs );
  49.  
  50.   if ( regs.x.cflag ) return status;
  51.  
  52.   return 0;
  53. }
  54.