C¾êÌ{ðvµÔèÉÇÝԵĢéÌÅ·ªAC^[|WVjO(interpose, interposition)Èé¾tðßÄmÁ½ÌÅÅ·B
uCWCuÖÈÇð[Jè`ÌÖÅã«Å«ÄµÜ¤vÆ¢¤¨bÅ·B¤Á©èâç©·ÆoOÌ·°ÉÈéÌÅ·ªA¤Üg¦ÎjbgeXgÌX^uƵÄÖ»¤B
timeÖÉ¢Ĩ³ç¢
áƵÄv¢Â¢½ÌÅAtime(3)ð㫵ÄÝÜ·B
time(3)Í»ÝðUNIX time(time_t^)Åæ¾·éCWCut®ÌÖÅ·BÚ×Íman 3 time
ÅB±ÌÖAÀsÔÉæÁÄʪíÉÙÈéí¯ÅAjbgeXgÌÍ¢èÒÅ·B
/* time_ex.c */
#include <stdio.h>
#include <time.h>
int main(void) {
printf("%ld", time(NULL));
return 0;
}
$ cc time_ex.c && ./a.out
(»ÝÉ·éunix timeª\¦³êé)
uàµAßO¾Á½çAðs¢Aßã¾Á½çBðs¤vu2015NÌ91úÈãÌÝLøÉÈéif¶vݽ¢ÈA»Ýðx[XÉðªò·éæ¤ÈWbNª éÆAʪÀèµÈ¢ÌŤÜjbgeXgª¯Ü¹ñB
timeÖðX^uÉÅ«ê΢¢í¯ÅA±±ÅC^[|WVjOªg¦Ü·B
C^[|WVjOÉæéã«
ܸÍy^y^¢ÄÝÜ·B
³Á«ÌmainÖÌOÉAÊÉtimeÖðè`µÜ·B
/* time_ex2.c */
#include <stdio.h>
#include <time.h>
time_t time(time_t* tloc) {
if (tloc == NULL) {
return 0;
}
return *tloc = 0;
}
int main(void) {
printf("%ld", time(NULL));
return 0;
}
$ cc time_ex2.c && ./a.out
0
½Ôñ½xÀsµÄà0ª\¦³êéæ¤ÉÈÁ½Í¸BRpCÉàA½ÌG[àoܹñB±êÍm©Éâç©·ÆCëɢoOÉÈé©àBB
±êÅX^uÉÍūܵ½ªA{â轩Á½vOðüϵĢéÌÆ Üèᢪ èܹñBeXgµ½¢¾¯A®IÉØèÖ¦½¢Æ±ëÅ·B
±ÌêAtimeÖ{ÌÌCuÍ_Ci~bNNµÄ龯ÈÌÅACuÌ[hð¢¶ÁÄâéÆAÈPÉã«Å«½èµÜ·B
X^uÌtimeÖðØ裷
X^uÌtimeÖ¾¯A_Ci~bNNpÌCuƵÄrh·êÎOKB ½¾AOSÉæÁıÌÓÌdgÝ;¢Ôá¤æ¤ÅAR}hàá¢Ü·B±±ÅÍMac OS XŵÄÝÜ·B
/* time_stub.c */
#include <time.h>
time_t time(time_t* tloc) {
if (tloc == NULL) {
return 0;
}
return *tloc = 0;
}
$ clang -shared -fPIC -o libtime_stub.dylib time_stub.c
$ ls
libtime_stub.dylib time_stub.c
m©ÅßÌMacÅÍ"gcc"R}hÍclangÌGCAXÉÈÁÄ¢éÌÅAclangÌãíèÉgccR}hðÅÁÄàÊͯ¶È͸B
ÆÍA±ÌoãªÁ½libtime_stub.dylibðWCuÌOÉÇÝܹÄAÀs·êÎOKBÅÌtime_ex.cðrhµ½a.outª¯¶fBNgÉ éƵÄA±ñÈ´¶Å·B
$ ./a.out
1442144345
$ DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES=libtime_stub.dylib ./a.out
0
«ÏðgÁÄAæÉX^uÌCuðÇÝܹé±ÆÅAtimeÖðã«Å«Üµ½I
àÁÆtime_stubÅVÔ
ðª¦ÎAÊɳÁ«Ìa.out¶áÈÄ௶æ¤ÉtimeÖð㫵½óÔÉÅ«Ü·B
á¦ÎAdateR}hBÀs·éÆ»Ýð\¦µÄêé͸ŷªAlibtime_stub.dylibÅÌ㫪LøÁÛ¢B
$ DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES=libtime_stub.dylib date
1970N 1 1ú Øjú 0900ª00b JST
1970NÉ^CXbvµ½Ý½¢Åyµ¢I »ë»ëÊ|³ÈÁÄ«½ÌÅexportµÄA¼ÌR}hàµÄÝÜ·B
$ export DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES=libtime_stub.dylib
$ date
1970N 1 1ú Øjú 0900ª00b JST
$ cal
1 1970
ú Î
Ø à y
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
$ perl -e 'print time();'
0
$ php -r 'echo date("c");'
1970-01-01T00:00:00+00:00
$ php -r 'echo date_create()->format("c");'
1970-01-01T00:00:00+00:00
$ ruby -e 'require "date"; puts DateTime.now'
2015-09-13T20:48:26+09:00
$ python -c 'import datetime; print datetime.datetime.now()'
2015-09-13 20:57:05.795197
$ node -e 'console.log(Date.now())'
1442145688533
ÓÞBBPHPâPerl¾Ætime(3)ðã«·êÎA®ÆµÄàã«Å«¿áÁÄéݽ¢Å·ËB RubyâPythonANode.jsÍe¿ðó¯È¢Ý½¢Å·BgÍSRmçÈ¢¯ÇAtime(3)ðgÁÄȢƢ¤±Æ©ÈcH
ÜÆß
- C¾êÅàWÖÌ㫪ūéæ
- ½¾ACuÌ[hð¢¶éâèûÍOS˶ªµ¢ÌÅAÅ«êÎð¯½Ù¤ª¢¢ÆÍv¤
- ¤Üg¦Îyµ»¤BÅàoOÌ´öÉàÈèâ·¢ÌÅCð¯é
C¾êà¶@ÌC¿«³ÉµêĵܦÎA·²ª[Äyµ¢Å·ËB
GLXp[gCvO~O\mçê´éCÌ[w (Ascii books)