gettimeofday

GETTIMEOFDAY(2)            Linux Programmer's Manual           GETTIMEOFDAY(2)



åå
       gettimeofday, settimeofday - æå»ãåå¾/è¨å®ãã

æ¸å¼
       #include <sys/time.h>

       int gettimeofday(struct timeval *tv, struct timezone *tz);

       int settimeofday(const struct timeval *tv, const struct timezone *tz);

   glibc åãã®æ©è½æ¤æ»ãã¯ãã®è¦ä»¶ (feature_test_macros(7)  åç§):

       settimeofday(): _BSD_SOURCE

説æ
       é¢æ° gettimeofday()  㨠settimeofday()  ã¯æå»ã¨ã¿ã¤ã ã¾ã¼ã³ãåå¾ã¾ãã¯è¨‐
       å®ããã tv å¼ãæ°ã¯ struct timeval ã§ãã (<sys/time.h> ã§å®ç¾©ããã¦ãã):

           struct timeval {
               time_t      tv_sec;     /* ç§ */
               suseconds_t tv_usec;    /* ãã¤ã¯ãç§ */
           };

       ããã«ããç´å (the Epoch: time(2)  ãåç§) ããã®ç§ã¨ãã¤ã¯ãç§ãåå¾ã§ããã tz
       å¼ãæ°ã¯ struct timezone ã§ãã:

           struct timezone {
               int tz_minuteswest;     /* ã°ãªããã¸æ¨æºæã¨ã®å·® (西æ¹ã«ååä½) */
               int tz_dsttime;         /* å¤æé調æ´ã®å */
           };

       tv ã tz ã NULL ã®å ´åã対å¿ããæ§é ä½ã®è¨å®/åå¾ã¯è¡ãããªã (ãã ããtv ã NULL
       ã®å ´åã«ã¯ãã³ã³ãã¤ã«æã®è¦åãçºçãã)ã

       timezone æ§é ä½ã®å©ç¨ã¯å»æ¢äºå®ã¨ããã¦ãã; é常㯠tz å¼ãæ°ã« NULL
       ãæå®ãã¹ãã§ãã (ä¸è¨ã®ã注æããåç§)ã

       Linux ã§ã¯ã settimeofday() ã·ã¹ãã ã³ã¼ã«ã«é¢é£ãã¦ãç¬ç¹ã®ãã¯ããã¯ã®ãºã¬
       (warp clock)ããåå¨ããå ´åãããã ãã㯠(ãã¼ãå¾ã®) æåã®å¼ã³åºã㧠tz å¼ãæ°ã
       NULL ã§ãªãã tv å¼ãæ°ã NULL 㧠tz_minuteswest ãã£ã¼ã«ã ã 0
       ã§ãªãå ´åã«èµ·ãã (ãã®å ´å tz_dsttime ãã£ã¼ã«ã㯠0 ã«ãã¹ãã§ãã)ã
       ãã®ãããªå ´åã settimeofday() 㯠CMOS ã¯ããã¯ãå°æ¹æ (local time) ã§ããã UTC
       ã·ã¹ãã æéãå¾ãããã«ã¯ãtz_minuteswest ã®åã ãå¢å ãããªãã¦ã¯ãªã
       ãªãã¨ã¿ãªãã¦ãã¾ãã çãããªãããã®æ©æ§ã使ããã¨ã¯è¯ãèãã§ã¯ãªãã

è¿ãå¤
       gettimeofday()  㨠settimeofday()  ã¯æåãã㨠0 ãè¿ãã失æããå ´å㯠-1 ãè¿ã
       (ãã®å ´å㯠errno ãé©åã«è¨å®ããã)ã

ã¨ã©ã¼
       EFAULT tv ã tz ã®ã©ã¡ãããã¢ã¯ã»ã¹å¯è½ãªã¢ãã¬ã¹ç©ºéå¤ãæãã¦ããã

       EINVAL ã¿ã¤ã ã¾ã¼ã³ (ã¾ãã¯ä»ã®ä½ã) ãä¸æ£ã§ããã

       EPERM  å¼ã³åºãåããã»ã¹ã« settimeofday()  ãå¼ã³åºãããã®ååãªç¹æ¨©ããªãã
              Linux ã§ã¯ CAP_SYS_TIME ã±ã¼ãããªã㣠(capability) ãå¿è¦ã§ããã

æºæ
       SVr4, 4.3BSD ã«æºæ ããã POSIX.1-2001 㯠gettimeofday()
       ã«ã¤ãã¦ã¯è¨è¿°ãã¦ãããã settimeofday()  ã«ã¤ãã¦ã¯è¨è¿°ãã¦ããªãã
       POSIX.1-2008 ã§ã¯ gettimeofday() ã¯å»æ¢äºå®ã¨ããã¦ããã 代ããã«
       clock_gettime(2)  ã®ä½¿ç¨ãæ¨å¥¨ããã¦ããã

注æ
       gettimeofday() ãè¿ãæå»ã¯ãã·ã¹ãã æéã®ä¸é£ç¶ãªå¤å
       (ä¾ãã°ãã·ã¹ãã 管çèãã·ã¹ãã æéãæåã§å¤æ´ããå ´åãªã©)
       ã®å½±é¿ãåãããå調å¢å ããã¯ããã¯ãå¿è¦ãªå ´åã¯ã clock_gettime(2)
       ãåç§ãã¦ã»ããã

       timeval æ§é ä½ãæä½ããããã®ãã¯ãã®èª¬æ㯠timeradd(3)  ã«ããã

       æ㯠struct timeval ã®ãã£ã¼ã«ã㯠long åã§ãã£ãã

       tz_dsttime 㯠Linux ã§ããã¾ã§ä½¿ããããã¨ã¯ãªãã ãããã£ã¦ã以ä¸ã¯ç´ç²ã«æ‐
       ´å²çãªèå³ããæ¸ããããã®ã§ããã

       tz_dsttime ãã£ã¼ã«ãã«ã¯ (ä¸è¨ã«ç¤ºã) ã·ã³ãã«å®æ°ãæ ¼ç´ãããã
       ããã¯ä¸å¹´ã®ãã¡ã§ãã¤å¤æé (Daylight Savings Time) ãå®æ½ãããã示ãã¦ãã
       (注æ: ãã®å¤ã¯å¹´éãéããå®æ°ã§ãã: å¤æéãå®æ½ä¸ã§ãããã¨ã示ãããã§ã¯ãªãã
       ã¢ã«ã´ãªãºã ãé¸æãã¦ããã ãã§ãã)ã å¤æéã¯ä»¥ä¸ã®ããã«å®ç¾©ããã:

           DST_NONE     /* å¤æéãæ¡ç¨ãã¦ããªã */
           DST_USA      /* ã¢ã¡ãªã«åè¡å½å¼å¤æé */
           DST_AUST     /* ãªã¼ã¹ãã©ãªã¢å¼å¤æé */
           DST_WET      /* 西ã¨ã¼ãããå¼å¤æé */
           DST_MET      /* ä¸å¤®ã¨ã¼ãããå¼å¤æé */
           DST_EET      /* æ±ã¨ã¼ãããå¼å¤æé */
           DST_CAN      /* ã«ãã */
           DST_GB       /* ã°ã¬ã¼ãããªãã³ããã³ã¢ã¤ã«ã©ã³ã */
           DST_RUM      /* ã«ã¼ãã㢠*/
           DST_TUR      /* ãã«ã³ */
           DST_AUSTALT  /* 1986å¹´ã«ç§»è¡ããããªã¼ã¹ãã©ãªã¢å¼ */

       å½ç¶ã®ãã¨ãªãããå¤æéãã©ã®æéã«å®æ½ãããããå½ãã¨ã®ç°¡åãªã¢ã«ã´ãªãºã ã§
       å°ããã¨ãã§ããªããã¨ãå¤æããã å®éãå¤æéã®æéã¯äºæ¸¬ä¸å¯è½ãªæ¿æ²»ç決å®ã§
       決å®ãããããã®ããããã®æ¹æ³ã§ã¿ã¤ã ã¾ã¼ã³ã表ããã¨ã¯æ念ãããã Linux ã«ããã¦
       settimeofday() ãå¼ã³åºãã¨ãã¯ã tz_dsttime ãã£ã¼ã«ãã 0 ã«ããã¹ãã§ããã

é¢é£é ç®
       date(1), adjtimex(2), clock_gettime(2), time(2), ctime(3), ftime(3),
       timeradd(3), capabilities(7), time(7)

ãã®ææ¸ã«ã¤ãã¦
       ãã® man ãã¼ã¸ã¯ Linux man-pages ããã¸ã§ã¯ãã®ãªãªã¼ã¹ 3.79 ã®ä¸é¨
       ã§ãããããã¸ã§ã¯ãã®èª¬æã¨ãã°å ±åã«é¢ããæå ±ã¯
       http://www.kernel.org/doc/man-pages/ ã«æ¸ããã¦ããã



Linux                             2012-04-26                   GETTIMEOFDAY(2)