Example #1
0
_WCRTLINK unsigned _dos_settime( struct dostime_t *time )
    {
        DATETIME    dt;

        DosGetDateTime( &dt );
        dt.hours        = time->hour;
        dt.minutes      = time->minute;
        dt.seconds      = time->second;
        dt.hundredths   = time->hsecond;
        return( DosSetDateTime( &dt ) );
    }
Example #2
0
int main(VOID) {



    DATETIME   DateTime = {0};       /* Structure to hold date/time info.   */

    APIRET     rc       = NO_ERROR;  /* Return code                         */



    rc = DosGetDateTime(&DateTime);  /* Retrieve the current date and time  */

    if (rc != NO_ERROR) {

        printf ("DosGetDateTime error : return code = %u\n", rc);

        return 1;

    }



    DateTime.hours = (UCHAR) ((BYTE) DateTime.hours + 1);    /* Set clock ahead

                                                 for Daylight Savings Time  */



    rc = DosSetDateTime(&DateTime);  /* Update the date and time            */



    if (rc!= NO_ERROR) {

        printf ("DosSetDateTime error : return code = %u\n", rc);

        return 1;

    }



    rc = DosGetDateTime(&DateTime);  /* Retrieve the date and time          */



    if (rc!= NO_ERROR) {

        printf ("DosGetDateTime error : return code = %u\n", rc);

        return 1;

    } else {

        printf("Today is %d-%d-%d; the time is now %d:%2.2d\n", DateTime.month,

               DateTime.day, DateTime.year, DateTime.hours, DateTime.minutes);

    }

    return NO_ERROR;

}
Example #3
0
File: time.c Project: DeadZen/qse
int qse_settime (const qse_ntime_t* t)
{
#if defined(_WIN32)
	FILETIME ft;
	SYSTEMTIME st;

	/**((qse_int64_t*)&ft) = ((t + EPOCH_DIFF_MSECS) * (10 * 1000));*/
	*((qse_int64_t*)&ft) = 
		(QSE_SEC_TO_NSEC(t->sec + EPOCH_DIFF_SECS) / 100)  + (t->nsec / 100);
	if (FileTimeToSystemTime (&ft, &st) == FALSE) return -1;
	if (SetSystemTime(&st) == FALSE) return -1;
	return 0;

#elif defined(__OS2__)

	APIRET rc;
	DATETIME dt;
	qse_btime_t bt;

	if (qse_localtime (t, &bt) <= -1) return -1;

	QSE_MEMSET (&dt, 0, QSE_SIZEOF(dt));
	dt.year = bt.year + QSE_BTIME_YEAR_BASE;
	dt.month = bt.mon + 1;
	dt.day = bt.mday;
	dt.hours = bt.hour;
	dt.minutes = bt.min;
	dt.seconds = bt.sec;
	dt.hundredths = QSE_NSEC_TO_MSEC(t->nsec) / 10;

	rc = DosSetDateTime (&dt);
	return (rc != NO_ERROR)? -1: 0;

#elif defined(__DOS__)

	struct dostime_t dt;
	struct dosdate_t dd;
	qse_btime_t bt;

	if (qse_localtime (t, &bt) <= -1) return -1;

	dd.year = bt.year + QSE_BTIME_YEAR_BASE;
	dd.month = bt.mon + 1;
	dd.day = bt.mday;
	dt.hour = bt.hour;
	dt.minute = bt.min;
	dt.second = bt.sec;
	dt.hsecond = QSE_NSEC_TO_MSEC(t->nsec) / 10;

	if (_dos_settime (&dt) != 0) return -1;
	if (_dos_setdate (&dd) != 0) return -1;

	return 0;

#elif defined(HAVE_SETTIMEOFDAY)
	struct timeval tv;
	int n;

	tv.tv_sec = t->sec;
	tv.tv_usec = QSE_NSEC_TO_USEC(t->nsec);

/*
#if defined(CLOCK_REALTIME) && defined(HAVE_CLOCK_SETTIME)
	{
		int r = clock_settime (CLOCK_REALTIME, ts);
		if (r == 0 || errno == EPERM) return r;
	}
#elif defined(HAVE_STIME)
	return stime (&ts->tv_sec);
#else
*/
	n = QSE_SETTIMEOFDAY (&tv, QSE_NULL);
	if (n == -1) return -1;
	return 0;

#else

	time_t tv;
	tv = t->sec;
	return (QSE_STIME (&tv) == -1)? -1: 0;
#endif
}