Mercurial > minori
comparison dep/utf8proc/bench/util.c @ 343:1faa72660932
*: transfer back to cmake from autotools
autotools just made lots of things more complicated than
they should have and many things broke (i.e. translations)
| author | Paper <paper@paper.us.eu.org> |
|---|---|
| date | Thu, 20 Jun 2024 05:56:06 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 342:adb79bdde329 | 343:1faa72660932 |
|---|---|
| 1 #include <stdio.h> | |
| 2 #include <stdlib.h> | |
| 3 #include <sys/stat.h> | |
| 4 | |
| 5 #include "util.h" | |
| 6 | |
| 7 /* read file named FILENAME into an array of *len bytes, | |
| 8 returning NULL on error */ | |
| 9 uint8_t *readfile(const char *filename, size_t *len) | |
| 10 { | |
| 11 *len = 0; | |
| 12 struct stat st; | |
| 13 if (0 != stat(filename, &st)) return NULL; | |
| 14 *len = st.st_size; | |
| 15 FILE *f = fopen(filename, "r"); | |
| 16 if (!f) return NULL; | |
| 17 uint8_t *s = (uint8_t *) malloc(sizeof(uint8_t) * *len); | |
| 18 if (!s) return NULL; | |
| 19 if (fread(s, 1, *len, f) != *len) { | |
| 20 free(s); | |
| 21 s = NULL; | |
| 22 } | |
| 23 fclose(f); | |
| 24 return s; | |
| 25 } | |
| 26 | |
| 27 mytime gettime(void) { | |
| 28 mytime t; | |
| 29 gettimeofday(&t, NULL); | |
| 30 return t; | |
| 31 } | |
| 32 | |
| 33 /* time difference in seconds */ | |
| 34 double elapsed(mytime t1, mytime t0) | |
| 35 { | |
| 36 return (double)(t1.tv_sec - t0.tv_sec) + | |
| 37 (double)(t1.tv_usec - t0.tv_usec) * 1.0E-6; | |
| 38 } | |
| 39 |
