home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 5.ddi / CLIBSRC2.ZIP / DOSSDATE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  3.2 KB  |  113 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - dossdate.c
  3.  *
  4.  * function(s)
  5.  *        _dos_setdate - sets MS-DOS date (MSC compatible)
  6.  *        _dos_settime - sets MS-DOS time (MSC compatible)
  7.  *-----------------------------------------------------------------------*/
  8.  
  9. /*
  10.  *      C/C++ Run Time Library - Version 5.0
  11.  *
  12.  *      Copyright (c) 1991, 1992 by Borland International
  13.  *      All Rights Reserved.
  14.  *
  15.  */
  16.  
  17.  
  18. #define _MSC
  19. #include <dos.h>
  20. #include <errno.h>
  21.  
  22. /*---------------------------------------------------------------------*
  23.  
  24. Name            _dos_setdate - sets MS-DOS date
  25.  
  26. Usage           #include <dos.h>
  27.                 unsigned _dos_setdate(struct dosdate_t *dateblk);
  28.  
  29. Prototype in    dos.h
  30.  
  31. Description     _dos_setdate the system's current date using the values
  32.                 in the dosdate_t structure (pointed to by dateblk).
  33.  
  34.                 The dosdate_t structure is defined as follows:
  35.  
  36.                 struct dosdate_t {
  37.                         unsigned char day;      (* 1-31 *)
  38.                         unsigned char month;    (* 1-12 *)
  39.                         unsigned int  year;     (* 1980 - 2099 *)
  40.                         unsigned char dayofweek;(* 0 - 6 (0=Sunday) *)
  41.                 };
  42.  
  43. Return value    If sucess, returns 0.  Otherwise, returns non-zero
  44.                 and sets errrno:
  45.  
  46.                         EINVAL  Invalid date
  47.  
  48. Note            Compatible with Microsoft C.  Not the same as setdate().
  49.  
  50. *---------------------------------------------------------------------*/
  51. unsigned _dos_setdate(struct dosdate_t *datep)
  52. {
  53.     _DH = datep->month;
  54.     _DL = datep->day;
  55.     _CX = datep->year;
  56.     _AH = 0x2b;
  57.     geninterrupt(0x21);
  58.     if (_AL == 0xff)
  59.     {
  60.         errno = EINVAL;
  61.         return -1U;
  62.     }
  63.     else
  64.         return 0;
  65. }
  66.  
  67.  
  68. /*---------------------------------------------------------------------*
  69.  
  70. Name            _dos_settime - sets MS-DOS time
  71.  
  72. Usage           #include <dos.h>
  73.                 unsigned _dos_settime(struct dostime_t *timep);
  74.  
  75. Prototype in    dos.h
  76.  
  77. Description     _dos_settime sets the system's current time to the values
  78.                 in the dostime_t structure pointed to by timep.
  79.  
  80.                 The dostime_t structure is defined as follows:
  81.  
  82.                 struct dostime_t {
  83.                         unsigned char hour;     (* Hours *)
  84.                         unsigned char minute;   (* Minutes *)
  85.                         unsigned char second;   (* Seconds *)
  86.                         unsigned char hsecond;  (* Hundredths of seconds *)
  87.                 };
  88.  
  89. Return value    If sucess, returns 0.  Otherwise, returns non-zero
  90.                 and sets errrno:
  91.  
  92.                         EINVAL  Invalid time
  93.  
  94. Note            Compatible with Microsoft C.  Not the same as settime().
  95.  
  96. *---------------------------------------------------------------------*/
  97. unsigned _dos_settime(struct dostime_t *timep)
  98. {
  99.     _CH = timep->hour;
  100.     _CL = timep->minute;
  101.     _DH = timep->second;
  102.     _DL = timep->hsecond;
  103.     _AH = 0x2d;
  104.     geninterrupt(0x21);
  105.     if (_AL == 0xff)
  106.     {
  107.         errno = EINVAL;
  108.         return -1U;
  109.     }
  110.     else
  111.         return 0;
  112. }
  113.