Fork me on GitHub

root/kernel/syscalls/gettimeofday.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. sys_gettimeofday

   1 /*
   2  * fiwix/kernel/syscalls/gettimeofday.c
   3  *
   4  * Copyright 2018, Jordi Sanfeliu. All rights reserved.
   5  * Distributed under the terms of the Fiwix License.
   6  */
   7 
   8 #include <fiwix/kernel.h>
   9 #include <fiwix/fs.h>
  10 #include <fiwix/process.h>
  11 #include <fiwix/time.h>
  12 #include <fiwix/timer.h>
  13 
  14 #ifdef __DEBUG__
  15 #include <fiwix/stdio.h>
  16 #endif /*__DEBUG__ */
  17 
  18 int sys_gettimeofday(struct timeval *tv, struct timezone *tz)
  19 {
  20         int errno;
  21 
  22 #ifdef __DEBUG__
  23         printk("(pid %d) sys_gettimeofday()\n", current->pid);
  24 #endif /*__DEBUG__ */
  25 
  26         if(tv) {
  27                 if((errno = check_user_area(VERIFY_WRITE, tv, sizeof(struct timeval)))) {
  28                         return errno;
  29                 }
  30                 tv->tv_sec = CURRENT_TIME;
  31                 tv->tv_usec = ((kstat.ticks % HZ) * 1000000) / HZ;
  32         }
  33         if(tz) {
  34                 if((errno = check_user_area(VERIFY_WRITE, tz, sizeof(struct timezone)))) {
  35                         return errno;
  36                 }
  37                 tz->tz_minuteswest = kstat.tz_minuteswest;
  38                 tz->tz_dsttime = kstat.tz_dsttime;
  39         }
  40         return 0;
  41 }

/* [previous][next][first][last][top][bottom][index][help] */