added ase_gettime() and ase_settime(), also added many builtin functions to ase_awk_opensimple()
This commit is contained in:
@ -7,6 +7,7 @@ libasecmn_la_SOURCES = mem.h chr.h \
|
||||
mem.c chr.c chr_cnv.c rex.c str_bas.c str_cnv.c str_dyn.c \
|
||||
lda.c map.c sll.c dll.c opt.c \
|
||||
fio.c sio.c tio.c tio_get.c tio_put.c \
|
||||
time.c \
|
||||
misc.c
|
||||
libasecmn_la_LDFLAGS = -version-info 1:0:0 -no-undefined
|
||||
|
||||
|
@ -53,7 +53,7 @@ LTLIBRARIES = $(lib_LTLIBRARIES)
|
||||
libasecmn_la_LIBADD =
|
||||
am_libasecmn_la_OBJECTS = mem.lo chr.lo chr_cnv.lo rex.lo str_bas.lo \
|
||||
str_cnv.lo str_dyn.lo lda.lo map.lo sll.lo dll.lo opt.lo \
|
||||
fio.lo sio.lo tio.lo tio_get.lo tio_put.lo misc.lo
|
||||
fio.lo sio.lo tio.lo tio_get.lo tio_put.lo time.lo misc.lo
|
||||
libasecmn_la_OBJECTS = $(am_libasecmn_la_OBJECTS)
|
||||
libasecmn_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
@ -204,6 +204,7 @@ libasecmn_la_SOURCES = mem.h chr.h \
|
||||
mem.c chr.c chr_cnv.c rex.c str_bas.c str_cnv.c str_dyn.c \
|
||||
lda.c map.c sll.c dll.c opt.c \
|
||||
fio.c sio.c tio.c tio_get.c tio_put.c \
|
||||
time.c \
|
||||
misc.c
|
||||
|
||||
libasecmn_la_LDFLAGS = -version-info 1:0:0 -no-undefined
|
||||
@ -291,6 +292,7 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_bas.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_cnv.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_dyn.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/time.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tio.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tio_get.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tio_put.Plo@am__quote@
|
||||
|
76
ase/lib/cmn/time.c
Normal file
76
ase/lib/cmn/time.c
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <ase/cmn/time.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#if defined(ASE_USE_SYSCALL) && defined(HAVE_SYS_SYSCALL_H)
|
||||
#include <sys/syscall.h>
|
||||
#endif
|
||||
|
||||
int ase_gettime (ase_time_t* t)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
SYSTEMTIME st;
|
||||
FILETIME ft;
|
||||
|
||||
/*
|
||||
* MSDN: The FILETIME structure is a 64-bit value representing the
|
||||
* number of 100-nanosecond intervals since January 1, 1601 (UTC).
|
||||
*/
|
||||
|
||||
GetSystemTime (&st);
|
||||
if (SystemTimeToFileTime (&st, &ft) == FALSE) return -1;
|
||||
*t = ((ase_time_t)(*((ase_int64_t*)&ft)) / (10 * 1000));
|
||||
*t -= EPOCH_DIFF_MSECS;
|
||||
return 0;
|
||||
#else
|
||||
struct timeval tv;
|
||||
int n;
|
||||
|
||||
#ifdef SYS_gettimeofday
|
||||
n = syscall (SYS_gettimeofday, &tv, ASE_NULL);
|
||||
#else
|
||||
n = gettimeofday (&tv, ASE_NULL);
|
||||
#endif
|
||||
if (n == -1) return -1;
|
||||
|
||||
*t = tv.tv_sec * ASE_MSEC_IN_SEC + tv.tv_usec / ASE_USEC_IN_MSEC;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int ase_settime (ase_time_t t)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
FILETIME ft;
|
||||
SYSTEMTIME st;
|
||||
|
||||
*((ase_int64_t*)&ft) = ((value + EPOCH_DIFF_MSECS) * (10 * 1000));
|
||||
if (FileTimeToSystemTime (&ft, &st) == FALSE) return -1;
|
||||
if (SetSystemTime(&st) == FALSE) return -1;
|
||||
return 0;
|
||||
#else
|
||||
struct timeval tv;
|
||||
int n;
|
||||
|
||||
tv.tv_sec = t / ASE_MSEC_IN_SEC;
|
||||
tv.tv_usec = (t % ASE_MSEC_IN_SEC) * ASE_USEC_IN_MSEC;
|
||||
|
||||
#ifdef SYS_settimeofday
|
||||
n = syscall (SYS_settimeofday, &tv, ASE_NULL);
|
||||
#else
|
||||
n = settimeofday (&tv, ASE_NULL);
|
||||
#endif
|
||||
if (n == -1) return -1;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user