Skip to content
Snippets Groups Projects
Commit c66554fa authored by Michal Vlasák's avatar Michal Vlasák
Browse files

Add documentation for `time_get`

parent 7176390f
No related branches found
No related tags found
No related merge requests found
Pipeline #265644 passed
...@@ -13,12 +13,14 @@ unreachable(char *file, size_t line) ...@@ -13,12 +13,14 @@ unreachable(char *file, size_t line)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
   
bool str_eq(Str a, Str b) bool
str_eq(Str a, Str b)
{ {
return a.len == b.len && memcmp(a.str, b.str, a.len) == 0; return a.len == b.len && memcmp(a.str, b.str, a.len) == 0;
} }
   
int str_cmp(Str a, Str b) int
str_cmp(Str a, Str b)
{ {
int cmp = memcmp(a.str, b.str, a.len < b.len ? a.len : b.len); int cmp = memcmp(a.str, b.str, a.len < b.len ? a.len : b.len);
return cmp == 0 ? (a.len > b.len) - (b.len > a.len) : cmp; return cmp == 0 ? (a.len > b.len) - (b.len > a.len) : cmp;
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
// See the bottom of this file for parser API. // See the bottom of this file for parser API.
   
// This header mainly defines the AST emitted by the reference FML parser and // This header mainly defines the AST emitted by the reference FML parser and
// a few utility types. // a few utility types and functions.
   
typedef uint8_t u8; typedef uint8_t u8;
typedef uint16_t u16; typedef uint16_t u16;
...@@ -46,9 +46,26 @@ bool str_eq(Str a, Str b); ...@@ -46,9 +46,26 @@ bool str_eq(Str a, Str b);
// - a positive number if the first string is greater than the second // - a positive number if the first string is greater than the second
int str_cmp(Str a, Str b); int str_cmp(Str a, Str b);
   
// Get current time and save it into `ts`.
// Get current time and save it into `ts`. Platform details may differ, but
// `struct timespec` should be at least similar to the following:
//
// struct timespec {
// long long tv_sec; /* seconds */
// long tv_nsec; /* nanoseconds */
// }
//
// An example of use:
//
// struct timespec ts;
// if (!time_get(&ts)) {
// exit(1);
// }
// printf("%lld%09ld\n", ts.tv_sec, ts.tv_nsec);
//
bool time_get(struct timespec *ts); bool time_get(struct timespec *ts);
   
// See https://courses.fit.cvut.cz/NI-RUN/specs/ast.html for details about the // See https://courses.fit.cvut.cz/NI-RUN/specs/ast.html for details about the
// AST. // AST.
   
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment