From ff11eca57680ad59b3ca5a6eeb1f402548e447a2 Mon Sep 17 00:00:00 2001 From: paladin-t Date: Tue, 2 Feb 2016 15:52:47 +0800 Subject: [PATCH] *added _ticks for apple and gnu compilers. --- core/my_basic.c | 4 ++-- makefile | 2 +- shell/main.c | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/core/my_basic.c b/core/my_basic.c index 33c0384..f709940 100755 --- a/core/my_basic.c +++ b/core/my_basic.c @@ -2158,7 +2158,7 @@ _ls_node_t* _ls_sort(_ls_node_t** list, _ls_compare cmp) { int insize, nmerges, psize, qsize, i; _ls_node_t* lst = 0; - mb_assert(list && cmp); + mb_assert(list && *list && cmp); lst = *list; if(lst) lst = lst->next; @@ -2775,7 +2775,7 @@ char* mb_strupr(char* s) { /** Unicode handling */ #ifdef MB_ENABLE_UNICODE int mb_uu_ischar(char* ch) { - /* Copyright 2008-2009 Bjoern Hoehrmann, http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ */ + /* Copyright 2008, 2009 Bjoern Hoehrmann, http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ */ /* Determine whether a buffer is a UTF8 encoded character, and return taken bytes */ #define _TAKE(__ch, __c, __r) do { __c = *__ch++; __r++; } while(0) #define _COPY(__ch, __c, __r, __cp) do { _TAKE(__ch, __c, __r); __cp = (__cp << 6) | ((unsigned char)__c & 0x3Fu); } while(0) diff --git a/makefile b/makefile index 6b0a9fb..feafdfb 100755 --- a/makefile +++ b/makefile @@ -1,5 +1,5 @@ my_basic : main.o my_basic.o - cc -o output/my_basic_bin main.o my_basic.o -lm + cc -o output/my_basic_bin main.o my_basic.o -lm -lrt main.o : shell/main.c core/my_basic.h cc -Os -c shell/main.c -Wno-unused-result diff --git a/shell/main.c b/shell/main.c index ebb93e7..b5f0cf5 100755 --- a/shell/main.c +++ b/shell/main.c @@ -37,6 +37,9 @@ #elif !defined __BORLANDC__ && !defined __TINYC__ # include #endif /* _MSC_VER */ +#ifndef _MSC_VER +# include +#endif /* _MSC_VER */ #include #include #include @@ -1077,6 +1080,14 @@ static int_t _ticks(void) { return ret; } +#elif defined __APPLE__ || defined __GNUC__ +static int_t _ticks(void) { + struct timespec ts; + + clock_gettime(CLOCK_MONOTONIC, &ts); + + return ts.tv_sec * 1000 + ts.tv_nsec / 1000000; +} #else /* _MSC_VER */ # undef _HAS_TICKS #endif /* _MSC_VER */