MXVM
1.8.1
Virtual Machine, Compiler, and Pascal Frontend
Loading...
Searching...
No Matches
io.c
Go to the documentation of this file.
1
6
#include <stdint.h>
7
#include <stdio.h>
8
#include <stdlib.h>
9
#include <string.h>
10
#include <time.h>
11
12
int64_t
fsize
(FILE *fptr) {
13
fseek(fptr, 0, SEEK_END);
14
int64_t total = ftell(fptr);
15
fseek(fptr, 0, SEEK_SET);
16
return
total;
17
}
18
19
int64_t
seed_random
() {
20
unsigned
int
seed = (
unsigned
int)time(NULL) ^ (uintptr_t)&seed;
21
srand(seed);
22
return
0;
23
}
24
25
int64_t
rand_number
(int64_t size) {
26
return
rand() % size;
27
}
28
29
char
*
mxvm_fgets
(FILE *fp) {
30
static
char
buf[4096];
31
char
*res = fgets(buf,
sizeof
(buf), fp);
32
if
(res) {
33
size_t
len = strlen(buf);
34
if
(len > 0 && buf[len - 1] ==
'\n'
)
35
buf[len - 1] =
'\0'
;
36
return
strdup(buf);
37
}
38
return
strdup(
""
);
39
}
rand_number
int64_t rand_number(int64_t size)
Definition
io.c:25
seed_random
int64_t seed_random()
Definition
io.c:19
mxvm_fgets
char * mxvm_fgets(FILE *fp)
Definition
io.c:29
fsize
int64_t fsize(FILE *fptr)
Definition
io.c:12
modules
io
io.c
Generated by
1.16.1