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

  1. /*-----------------------------------------------------------------------*
  2.  * filename - strdate.c
  3.  *
  4.  * function(s)
  5.  *        _strdate - gets MS-DOS date string (MSC compatible)
  6.  *        _strtime - gets MS-DOS time string (MSC compatible)
  7.  *-----------------------------------------------------------------------*/
  8.  
  9. /*
  10.  *      C/C++ Run Time Library - Version 5.0
  11.  *
  12.  *      Copyright (c) 1987, 1992 by Borland International
  13.  *      All Rights Reserved.
  14.  *
  15.  */
  16.  
  17.  
  18. #include <dos.h>
  19. #include <time.h>
  20.  
  21. /*---------------------------------------------------------------------*
  22.  
  23. Name            makedate - make a date or time string
  24.  
  25. Usage           char *makedate(char *str,int one,int two,int three,
  26.                                char sep);
  27.  
  28. Description     Makes a date or time string in the form xxsyysz,
  29.                 where xx, yy, and zz are two digit decimal representations
  30.                 of the parameters one, two, and three, respectively,
  31.                 and s is the separator character sep.  The string
  32.                 is terminated by a null
  33.  
  34. Return value    The value of str.
  35.  
  36. *---------------------------------------------------------------------*/
  37.  
  38. static char * pascal near
  39. makedate(char *str,int one,int two,int three, char sep)
  40. {
  41.     str[2] = str[5] = sep;
  42.     str[8] = '\0';
  43.     str[0] = ((one / 10) % 10) + '0';
  44.     str[1] = (one % 10) + '0';
  45.     str[3] = ((two / 10) % 10) + '0';
  46.     str[4] = (two % 10) + '0';
  47.     str[6] = ((three / 10) % 10) + '0';
  48.     str[7] = (three % 10) + '0';
  49.     return (str);
  50. }
  51.  
  52. /*---------------------------------------------------------------------*
  53.  
  54. Name            _strdate - copies MS-DOS date to a string buffer
  55.  
  56. Usage           #include <time.h>
  57.                 char *_strdate(char *datestr);
  58.  
  59. Prototype in    dos.h
  60.  
  61. Description     _strdate copies the current system date to a buffer
  62.                 pointed to by datestr, in the following format:
  63.  
  64.                         mm/dd/yy
  65.  
  66.                 where mm is two digits representing the month, dd is two
  67.                 digits representing the day, and yy is two digits
  68.                 representing the year. The string thus formed is
  69.                 terminated by a null character.
  70.                 The buffer must be at least 9 bytes long.
  71.  
  72. Return value    The value of datestr.
  73.  
  74. Note            Compatible with Microsoft C.
  75.  
  76. *---------------------------------------------------------------------*/
  77.  
  78. char * _FARFUNC _strdate(char *datestr)
  79. {
  80.     struct dosdate_t d;
  81.  
  82.     _dos_getdate(&d);
  83.     return (makedate(datestr,d.month,d.day,d.year-1900,'/'));
  84. }
  85.  
  86. /*---------------------------------------------------------------------*
  87.  
  88. Name            _strtime - copies MS-DOS time to a string buffer
  89.  
  90. Usage           #include <time.h>
  91.                 char *_strtime(char *timestr);
  92.  
  93. Prototype in    dos.h
  94.  
  95. Description     _strtime copies the current system time to a buffer
  96.                 pointed to by timestr, in the following format:
  97.  
  98.                 hh/mm/ss
  99.  
  100.                 where hh is two digits representing the hour, mm is two
  101.                 digits representing the minutes, and yy is two digits
  102.                 representing the seconds. The string thus formed is
  103.                 terminated by a null character.
  104.                 The buffer must be at least 9 bytes long.
  105.  
  106. Return value    The value of timestr.
  107.  
  108. Note            Compatible with Microsoft C.
  109.  
  110. *---------------------------------------------------------------------*/
  111.  
  112. char * _FARFUNC _strtime(char *timestr)
  113. {
  114.     struct dostime_t t;
  115.  
  116.     _dos_gettime(&t);
  117.     return (makedate(timestr,t.hour,t.minute,t.second,':'));
  118. }
  119.