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

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)  */
  2.  
  3. #include "tools.h"
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <dos.h>
  7.  
  8.  
  9. /***
  10.  *
  11.  *  Function   :    gettmppath
  12.  *
  13.  *  Topics     :    Transforms a filename into a full pathname
  14.  *                  relative to temporary directory.
  15.  *
  16.  *  Parameters :    in/out  char *filename    filename
  17.  *
  18.  *  Return     :    pointer to filename
  19.  *
  20.  ***/
  21.  
  22. char *gettmppath( char *filename )
  23.  
  24. { char *ptr;
  25.  
  26.   ptr = getenv( "TEMP" );
  27.   if ( ! ptr || ! *ptr ) ptr = getenv( "temp" );
  28.   if ( ! ptr || ! *ptr ) ptr = getenv( "TMP" );
  29.   if ( ! ptr || ! *ptr ) ptr = getenv( "tmp" );
  30.  
  31.   if ( ptr && *ptr ) { char buffer[_MAX_PATH];
  32.                        strcpy( buffer, filename );
  33.                        _makepath( filename, "", ptr, buffer, "");
  34.                        strupr( filename );
  35.                      }
  36.                 else getpgmpath( filename );
  37.  
  38.   return filename;
  39. }
  40.  
  41.  
  42. #ifdef MAIN
  43.  
  44. #include <stdio.h>
  45. #include <conio.h>
  46. void main( void )
  47.  
  48. { char f[_MAX_PATH] = "abc.ext";
  49.  
  50.   putenv( "TEMP=e:\\tmp" );
  51.   putenv( "TMP=c:\\tmp" );
  52.   clrscr();
  53.   printf( "%s\n", gettmppath(f) );
  54.   getch();
  55. }
  56.  
  57. #endif
  58.