aboutsummaryrefslogtreecommitdiff
path: root/std/stdlib.c
blob: dcb7ec31fefe3a6183a381036afa9cce9f741e97 (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

int wait(int msec) {
    struct timespec ts;
    int res;

    if (msec < 0)
    {
        errno = EINVAL;
        return -1;
    }

    ts.tv_sec = msec / 1000;
    ts.tv_nsec = (msec % 1000) * 1000000;

    do {
        res = nanosleep(&ts, &ts);
    } while (res && errno == EINTR);

    return res;
}

int slen(char *str) {
    return (int) strlen(str);
}

char charAt(char *str, int x) {
    return str[x];
}

int parse_int(char *str) {
    return (int) atoi(str);
}

int as_int(float x) {
    return (int) x;
}

// char* istr(int x) {
//     char snum[100];
//     return (char* )itoa(x, snum, 10);
// }