home *** CD-ROM | disk | FTP | other *** search
- /*
- * osdate - return the last date of modification of the given file
- * this version for Microsoft C medium or small memory model
- * will require modification to get the segment offset of the
- * file on open operation to work with large memory model.
- *
- * This file replaces osdate.asm in Landon M. Dyer's 'Make' program for
- * MS-DOS when using Microsoft C (the rest compiles OK).
- *
- * Author: Nick Thompson, South Bank Polytechnic, London.
- *
- * --------------------------------------------------------------
- * "You can do what you will with this code, but don't sell it!!"
- * --------------------------------------------------------------
- *
- * Note: as the program does not need large memory support all the
- * large stuff is commented out. I have tested this fregment
- * with both medium and small models, but not large. I have
- * put in what I think is needed (but it is not tested).
- *
- */
-
-
- #include <dos.h>
- #include <stdio.h>
-
- #define DOS_CALL 0x21 /* symbolic constants representing*/
- #define OPEN_FILE 0x3D /* the O/S calls to make */
- #define GET_DATE_TIME 0x57
- #define CLOSE_FILE 0x3E
-
- int osdate(name, time1, time2) /* get time of last modification*/
- char *name; /* for this file "name" */
- int *time1; /* time (least significant) */
- int *time2; /* date (most significant) */
- {
- int result; /* stores the result of DOS call*/
- int handle; /* stores file handle */
- union REGS inregs, outregs; /* registers for DOS call */
-
- /* struct SREGS segregs;*/ /* you will need this for large memory model*/
-
-
- /* try to open the file */
-
- inregs.h.ah = OPEN_FILE; /* DOS function call */
- inregs.h.al = 1; /* mode */
- inregs.x.dx = FP_OFF(name); /* offset of ptr to filename */
-
- /* segregs.ds = FP_SEG(name); */ /* large memory model */
- /* result = int86x(DOS_CALL, &inregs, &outregs, &segregs);*//*large model*/
-
- result = int86(DOS_CALL, &inregs, &outregs); /* open it */
- if(outregs.x.cflag) { /* check for error */
-
- return(-1);
-
- }
- else {
- handle = outregs.x.ax; /* assign file handle */
- }
-
- inregs.x.bx = handle; /* put handle returned by the */
- /* open operation into bx */
-
- inregs.h.ah = GET_DATE_TIME; /* dos function to call */
- inregs.h.al = 0; /* al = 0 so get time */
-
- result = int86(DOS_CALL, &inregs, &outregs); /* do it */
- if(outregs.x.cflag) { /* has an error occured */
- printf("Can't obtain file date/time: Error code = %d\n", result);
- inregs.h.ah = CLOSE_FILE; /* clean up */
- inregs.h.al = 0;
- result = int86(DOS_CALL, &inregs, &outregs);
- if(outregs.x.cflag) {
- printf("Can't close file: Error code = %d\n", result);
- }
- return(-1); /* and go home */
- }
-
-
- *time1 = (int)outregs.x.cx; /* time (least significant) */
- *time2 = (int)outregs.x.dx; /* date (most significant) */
-
- inregs.h.ah = CLOSE_FILE; /* close up the file */
- inregs.h.al = 0;
-
- result = int86(DOS_CALL, &inregs, &outregs);
- if(outregs.x.cflag) {
- printf("Can't close file: Error code = %d\n", result);
- return(-1);
- }
-
- return(0);
- }
-
-