Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1906 serge 1
/* Reentrant version of gettimeofday system call
2
   This implementation just calls the times/gettimeofday system calls.
3
   Gettimeofday may not be available on all targets.  It's presence
4
   here is dubious.  Consider it for internal use only.  */
5
 
6
#include 
7
#include 
8
#include 
9
#include 
10
#include <_syslist.h>
11
#include 
12
 
13
/* Some targets provides their own versions of these functions.  Those
14
   targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS.  */
15
 
16
#ifdef _REENT_ONLY
17
#ifndef REENTRANT_SYSCALLS_PROVIDED
18
#define REENTRANT_SYSCALLS_PROVIDED
19
#endif
20
#endif
21
 
22
#ifdef REENTRANT_SYSCALLS_PROVIDED
23
 
24
int _dummy_gettimeofday_syscalls = 1;
25
 
26
#else
27
 
28
/* We use the errno variable used by the system dependent layer.  */
29
#undef errno
30
static int errno;
31
 
32
/*
33
FUNCTION
34
	<<_gettimeofday_r>>---Reentrant version of gettimeofday
35
 
36
INDEX
37
	_gettimeofday_r
38
 
39
ANSI_SYNOPSIS
40
	#include 
41
	#include 
42
	int _gettimeofday_r(struct _reent *<[ptr]>,
43
		struct timeval *<[ptimeval]>,
44
		void *<[ptimezone]>);
45
 
46
TRAD_SYNOPSIS
47
	#include 
48
	#include 
49
	int _gettimeofday_r(<[ptr]>, <[ptimeval]>, <[ptimezone]>)
50
	struct _reent *<[ptr]>;
51
	struct timeval *<[ptimeval]>;
52
	void *<[ptimezone]>;
53
 
54
DESCRIPTION
55
	This is a reentrant version of <>.  It
56
	takes a pointer to the global data block, which holds
57
	<>.
58
 
59
	This function is only available for a few targets.
60
	Check libc.a to see if its available on yours.
61
*/
62
 
63
int
64
_DEFUN (_gettimeofday_r, (ptr, ptimeval, ptimezone),
65
     struct _reent *ptr _AND
66
     struct timeval *ptimeval _AND
67
     void *ptimezone)
68
{
69
  int ret;
70
 
71
  errno = 0;
72
  if ((ret = _gettimeofday (ptimeval, ptimezone)) == -1 && errno != 0)
73
    ptr->_errno = errno;
74
  return ret;
75
}
76
 
77
#define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
78
 
79
int
80
_gettimeofday (struct timeval *tv, void *tz)
81
{
82
    unsigned int xtmp;
83
    struct   tm tmblk;
84
 
85
    if( tv )
86
    {
87
        tv->tv_usec = 0;
88
 
89
         __asm__ __volatile__("int $0x40":"=a"(xtmp):"0"(3));
90
        tmblk.tm_sec = (xtmp>>16)&0xff;
91
        tmblk.tm_min = (xtmp>>8)&0xff;
92
        tmblk.tm_hour = xtmp&0xff;
93
        BCD_TO_BIN(tmblk.tm_sec);
94
        BCD_TO_BIN(tmblk.tm_min);
95
        BCD_TO_BIN(tmblk.tm_hour);
96
        __asm__ __volatile__("int $0x40":"=a"(xtmp):"0"(29));
97
        tmblk.tm_mday = (xtmp>>16)&0xff;
98
        tmblk.tm_mon = ((xtmp>>8)&0xff)-1;
99
        tmblk.tm_year = ((xtmp&0xff)+2000)-1900;
100
        tmblk.tm_wday = tmblk.tm_yday = 0;
101
        tmblk.tm_isdst = -1;
102
        tv->tv_sec = mktime(&tmblk);
103
        return 0;
104
    }
105
    else
106
    {
107
        errno = EINVAL;
108
        return -1;
109
    };
110
}
111
 
112
 
113
#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */