⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 settod.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
字号:
/*
 *  settimeofday() for non-djgpp targets
 *
 *  The exported prototype used is used is the one specified in the 
 *  XOpen/POSIX 1.3 standards and the one used on modern (ie 4.4BSD spec) 
 *  BSDs. ie 'int settimeofday(struct timeval *, ...)', ie the second
 *  arg, if specified, is ignored.
 *  
 *  Cyrus Patel <cyp@fb14.uni-mainz.de>
 *
 *  May 2001 - Created
 *
 */

#if !defined(__DJGPP__) /* djgpp already has settimeofday */

#include <dos.h>        /* _dos_setdate, _dos_settime, dosdate_t, dostime_t */
#include <errno.h>      /* EINVAL */

#include "../inc/tcp.h" /* time func/types */
#include "settod.h"

int settimeofday (struct timeval *tv, ...)
{
  if (tv)
  {
    time_t t = (time_t)tv->tv_sec;
    struct tm *tmp = localtime (&t);

    if (tmp->tm_year >= 80)
    {
      /* every dosish OS should have these.
       * TurboC/BorlandC, WatcomC and DJGPP definitely do.
       */
      struct dosdate_t newdate;
      struct dostime_t newtime;

      newdate.year    = (WORD)(tmp->tm_year + 1900);
      newdate.month   = (BYTE)(tmp->tm_mon + 1);
      newdate.day     = (BYTE)(tmp->tm_mday);
      newtime.hour    = (BYTE)(tmp->tm_hour);
      newtime.minute  = (BYTE)(tmp->tm_min);
      newtime.second  = (BYTE)(tmp->tm_sec);
      newtime.hsecond = (BYTE)(tv->tv_usec / 10000ul);
      if (_dos_setdate(&newdate) == 0  && /* int 21h fxn 2Bh */
          _dos_settime(&newtime) == 0)    /* int 21h fxn 2Dh */
        return (0);
    }
  }
  errno = EINVAL;
  return (-1);
}  

#endif /* !defined(__DJGPP__) */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -