Download code/validation/C/0018807_common.c from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 3.74 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/code/validation/C/0018807_common.c
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/code/validation/C/0018807_common.c
-
curl -L -o 0018807_common.c https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/code/validation/C/0018807_common.c
3.74 kB
| /*--------------------------------------------- | |
| * modification time: 2016.12.18 01:15 | |
| * mender: Muse | |
| -*---------------------------------------------*/ | |
| /*--------------------------------------------- | |
| * creation time: 2016.12.05 14:15 | |
| * author: Muse | |
| -*---------------------------------------------*/ | |
| /*--------------------------------------------- | |
| * Source file content Seven part | |
| * | |
| * Part Zero: Include | |
| * Part One: Define | |
| * Part Two: Local data | |
| * Part Three: Local function | |
| * | |
| * Part Four: i/o | |
| * Part Five: string | |
| * Part Six: random | |
| * | |
| -*---------------------------------------------*/ | |
| /*--------------------------------------------- | |
| * Part Zero: Include | |
| -*---------------------------------------------*/ | |
| /*--------------------------------------------- | |
| * Part One: Define | |
| -*---------------------------------------------*/ | |
| /*--------------------------------------------- | |
| * Part Four: i/o | |
| * | |
| * 1. readnonblock | |
| * 2. writen | |
| * 3. strnstr | |
| * 4. strnchr | |
| * 5. atoin | |
| * | |
| -*---------------------------------------------*/ | |
| /*-----readnonblock-----*/ | |
| int32_t readnonblock(int32_t fd, void *buf, size_t count) | |
| { | |
| int32_t res, offset = 0; | |
| while (true) { | |
| if ((res = read(fd, buf + offset, count)) == count) { | |
| return offset + res; | |
| } else if (res == CERR && errno == EAGAIN) { | |
| return offset; | |
| } else { | |
| if (res != CERR) { | |
| offset += res; | |
| count -= res; | |
| } | |
| } | |
| } | |
| } | |
| /*-----writen-----*/ | |
| int32_t writen(int32_t fd, void *buf, size_t count) | |
| { | |
| int32_t res, offset = 0; | |
| while (true) { | |
| if ((res = write(fd, buf + offset, count)) == count) { | |
| return offset + res; | |
| } else if (res >= 0) { | |
| offset += res; | |
| count -= res; | |
| } else { | |
| return offset; | |
| } | |
| } | |
| } | |
| /*--------------------------------------------- | |
| * Part Five: string | |
| * | |
| * 1. strnstr | |
| * 2. strnchr | |
| * 3. atoin | |
| * | |
| -*---------------------------------------------*/ | |
| /*-----strnstr-----*/ | |
| char *strnstr(char *haystack, const char *needle, int32_t offset) | |
| { | |
| char *str, ch; | |
| CHECK_STR(!needle, NULL); | |
| TRUN_STR(); | |
| str = strstr(haystack, needle); | |
| JOIN_STR(); | |
| return str; | |
| } | |
| /*-----strnchr-----*/ | |
| char *strnchr(char *haystack, char c, int32_t offset, bool is_first) | |
| { | |
| char *str, ch; | |
| CHECK_STR(false, NULL); | |
| if (haystack[offset] == c) | |
| return &haystack[offset]; | |
| TRUN_STR(); | |
| str = (is_first) ? strchr(haystack, c) : strrchr(haystack, c); | |
| JOIN_STR(); | |
| return str; | |
| } | |
| /*-----atoin-----*/ | |
| int32_t atoin(char *haystack, int32_t offset) | |
| { | |
| char ch; | |
| int32_t result; | |
| CHECK_STR(false, CERR); | |
| TRUN_STR(); | |
| result = atoi(haystack); | |
| JOIN_STR(); | |
| return result; | |
| } | |
| /*--------------------------------------------- | |
| * Part Six: random | |
| * | |
| * 1. trandom | |
| * 2. clockrandom | |
| * | |
| -*---------------------------------------------*/ | |
| /*-----trandom-----*/ | |
| int64_t trandom(int32_t mod) | |
| { | |
| srand48(clock()); | |
| return (lrand48() % mod); | |
| } | |
| /*-----clockrandom-----*/ | |
| int64_t clockrandom(int32_t mod) | |
| { | |
| return clock() % mod; | |
| } | |