home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume7 / msdos_mk.patch / osdate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  3.0 KB  |  98 lines

  1. /*
  2.  * osdate - return the last date of modification of the given file
  3.  *        this version for Microsoft C medium or small memory model
  4.  *        will require modification to get the segment offset of the
  5.  *        file on open operation to work with large memory model.
  6.  *
  7.  * This file replaces osdate.asm in Landon M. Dyer's 'Make' program for
  8.  * MS-DOS when using Microsoft C (the rest compiles OK).
  9.  *
  10.  * Author: Nick Thompson, South Bank Polytechnic, London.
  11.  *
  12.  * --------------------------------------------------------------
  13.  * "You can do what you will with this code, but don't sell it!!"
  14.  * --------------------------------------------------------------
  15.  *
  16.  * Note: as the program does not need large memory support all the
  17.  *     large stuff is commented out.  I have tested this fregment
  18.  *     with both medium and small models, but not large.  I have
  19.  *     put in what I think is needed (but it is not tested).
  20.  *
  21.  */
  22.  
  23.  
  24. #include <dos.h>
  25. #include <stdio.h>
  26.  
  27. #define DOS_CALL    0x21        /* symbolic constants representing*/
  28. #define    OPEN_FILE    0x3D        /* the O/S calls to make    */
  29. #define    GET_DATE_TIME    0x57
  30. #define    CLOSE_FILE    0x3E
  31.  
  32. int osdate(name, time1, time2)        /* get time of last modification*/
  33. char *name;                /*  for this file "name"    */
  34. int  *time1;                /*  time (least significant)    */
  35. int  *time2;                /*  date (most significant)    */
  36. {
  37.     int result;            /* stores the result of DOS call*/
  38.     int handle;            /* stores file handle        */
  39.     union REGS inregs, outregs;    /* registers for DOS call    */
  40.  
  41. /*    struct SREGS segregs;*/    /* you will need this for large memory model*/
  42.  
  43.  
  44.     /* try to open the file    */
  45.  
  46.     inregs.h.ah = OPEN_FILE;    /* DOS function call        */
  47.     inregs.h.al = 1;        /* mode                */
  48.     inregs.x.dx = FP_OFF(name);    /* offset of ptr to filename    */
  49.  
  50. /*    segregs.ds = FP_SEG(name); */    /* large memory model        */
  51. /*    result = int86x(DOS_CALL, &inregs, &outregs, &segregs);*//*large model*/
  52.  
  53.     result = int86(DOS_CALL, &inregs, &outregs);    /* open it    */
  54.     if(outregs.x.cflag) {        /* check for error        */
  55.  
  56.         return(-1);
  57.  
  58.     }
  59.     else {
  60.             handle = outregs.x.ax;    /* assign file handle        */
  61.     }
  62.  
  63.     inregs.x.bx = handle;        /* put handle returned by the    */
  64.                     /* open operation into bx    */
  65.  
  66.     inregs.h.ah = GET_DATE_TIME;    /* dos function to call        */
  67.     inregs.h.al = 0;        /* al = 0 so get time         */
  68.  
  69.     result = int86(DOS_CALL, &inregs, &outregs);    /* do it    */
  70.     if(outregs.x.cflag) {        /* has an error occured        */
  71.         printf("Can't obtain file date/time: Error code = %d\n", result);
  72.         inregs.h.ah = CLOSE_FILE;        /* clean up    */
  73.         inregs.h.al = 0;
  74.         result = int86(DOS_CALL, &inregs, &outregs);
  75.         if(outregs.x.cflag) {
  76.             printf("Can't close file: Error code = %d\n", result);
  77.         }
  78.         return(-1);        /* and go home            */
  79.     }
  80.  
  81.  
  82.         *time1 = (int)outregs.x.cx;    /* time (least significant)    */
  83.         *time2 = (int)outregs.x.dx;     /* date (most significant)    */
  84.  
  85.     inregs.h.ah = CLOSE_FILE;    /* close up the file        */
  86.     inregs.h.al = 0;
  87.  
  88.     result = int86(DOS_CALL, &inregs, &outregs);
  89.     if(outregs.x.cflag) {
  90.         printf("Can't close file: Error code = %d\n", result);
  91.         return(-1);
  92.     }
  93.  
  94.     return(0);
  95. }
  96.  
  97. 
  98.