1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
/*
* <sys/stat.h> wrapper functions.
*
* Authors:
* Jonathan Pryor (jonpryor@vt.edu)
*
* Copyright (C) 2004-2006 Jonathan Pryor
*/
#include <sys/types.h>
#include <sys/time.h>
#include <string.h>
#ifdef __HAIKU__
#include <os/kernel/OS.h>
#endif
#include "map.h"
#include "mph.h"
G_BEGIN_DECLS
gint32
Mono_Posix_Syscall_gettimeofday (
struct Mono_Posix_Timeval *tv,
void *tz)
{
struct timeval _tv;
struct timezone _tz;
int r;
r = gettimeofday (&_tv, &_tz);
if (r == 0) {
if (tv) {
tv->tv_sec = _tv.tv_sec;
tv->tv_usec = _tv.tv_usec;
}
if (tz) {
struct Mono_Posix_Timezone *tz_ = (struct Mono_Posix_Timezone *) tz;
tz_->tz_minuteswest = _tz.tz_minuteswest;
tz_->tz_dsttime = 0;
}
}
return r;
}
gint32
Mono_Posix_Syscall_settimeofday (
struct Mono_Posix_Timeval *tv,
struct Mono_Posix_Timezone *tz)
{
struct timeval _tv = {0};
struct timeval *ptv = NULL;
struct timezone _tz = {0};
struct timezone *ptz = NULL;
int r;
if (tv) {
_tv.tv_sec = tv->tv_sec;
_tv.tv_usec = tv->tv_usec;
ptv = &_tv;
}
if (tz) {
_tz.tz_minuteswest = tz->tz_minuteswest;
_tz.tz_dsttime = 0;
ptz = &_tz;
}
#ifdef __HAIKU__
set_real_time_clock(ptv->tv_sec);
r = 0;
#else
r = settimeofday (ptv, ptz);
#endif
return r;
}
static struct timeval*
copy_utimes (struct timeval* to, struct Mono_Posix_Timeval *from)
{
if (from) {
to[0].tv_sec = from[0].tv_sec;
to[0].tv_usec = from[0].tv_usec;
to[1].tv_sec = from[1].tv_sec;
to[1].tv_usec = from[1].tv_usec;
return to;
}
return NULL;
}
gint32
Mono_Posix_Syscall_utimes(const char *filename, struct Mono_Posix_Timeval *tv)
{
struct timeval _tv[2];
struct timeval *ptv;
ptv = copy_utimes (_tv, tv);
return utimes (filename, ptv);
}
#ifdef HAVE_LUTIMES
gint32
Mono_Posix_Syscall_lutimes(const char *filename, struct Mono_Posix_Timeval *tv)
{
struct timeval _tv[2];
struct timeval *ptv;
ptv = copy_utimes (_tv, tv);
return lutimes (filename, ptv);
}
#endif /* def HAVE_LUTIMES */
#if HAVE_FUTIMES
gint32
Mono_Posix_Syscall_futimes(int fd, struct Mono_Posix_Timeval *tv)
{
struct timeval _tv[2];
struct timeval *ptv;
ptv = copy_utimes (_tv, tv);
return futimes (fd, ptv);
}
#endif /* def HAVE_FUTIMES */
G_END_DECLS
/*
* vim: noexpandtab
*/
|