Rizin
unix-like reverse engineering framework and cli tools
main.c
Go to the documentation of this file.
1
#include <stdio.h>
2
3
#include <
uv.h
>
4
5
uv_loop_t
*
loop
;
6
uv_fs_t
stdin_watcher
;
7
uv_idle_t
idler
;
8
char
buffer
[1024];
9
10
void
crunch_away
(
uv_idle_t
*
handle
) {
11
// Compute extra-terrestrial life
12
// fold proteins
13
// computer another digit of PI
14
// or similar
15
fprintf(stderr,
"Computing PI...\n"
);
16
// just to avoid overwhelming your terminal emulator
17
uv_idle_stop
(
handle
);
18
}
19
20
void
on_type
(
uv_fs_t
*
req
) {
21
if
(
stdin_watcher
.
result
> 0) {
22
buffer
[
stdin_watcher
.
result
] =
'\0'
;
23
printf
(
"Typed %s\n"
,
buffer
);
24
25
uv_buf_t
buf
=
uv_buf_init
(
buffer
, 1024);
26
uv_fs_read
(
loop
, &
stdin_watcher
, 0, &
buf
, 1, -1,
on_type
);
27
uv_idle_start
(&
idler
,
crunch_away
);
28
}
29
else
if
(
stdin_watcher
.
result
< 0) {
30
fprintf(stderr,
"error opening file: %s\n"
,
uv_strerror
(
req
->result));
31
}
32
}
33
34
int
main
() {
35
loop
=
uv_default_loop
();
36
37
uv_idle_init
(
loop
, &
idler
);
38
39
uv_buf_t
buf
=
uv_buf_init
(
buffer
, 1024);
40
uv_fs_read
(
loop
, &
stdin_watcher
, 0, &
buf
, 1, -1,
on_type
);
41
uv_idle_start
(&
idler
,
crunch_away
);
42
return
uv_run
(
loop
,
UV_RUN_DEFAULT
);
43
}
handle
static mcore_handle handle
Definition:
asm_mcore.c:8
printf
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition:
cs_driver.c:93
req
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec req
Definition:
sflib.h:128
buf
voidpf void * buf
Definition:
ioapi.h:138
main
int main(int argc, const char **argv)
Definition:
main.c:340
buffer
Definition:
buffer.h:15
uv_buf_t
Definition:
unix.h:123
uv_fs_s
Definition:
uv.h:1306
uv_fs_s::result
ssize_t result
Definition:
uv.h:1311
uv_idle_s
Definition:
uv.h:834
uv_loop_s
Definition:
uv.h:1780
loop
uv_loop_t * loop
Definition:
main.c:7
crunch_away
void crunch_away(uv_idle_t *handle)
Definition:
main.c:10
stdin_watcher
uv_fs_t stdin_watcher
Definition:
main.c:6
on_type
void on_type(uv_fs_t *req)
Definition:
main.c:20
idler
uv_idle_t idler
Definition:
main.c:7
uv.h
UV_RUN_DEFAULT
@ UV_RUN_DEFAULT
Definition:
uv.h:255
uv_fs_read
UV_EXTERN int uv_fs_read(uv_loop_t *loop, uv_fs_t *req, uv_file file, const uv_buf_t bufs[], unsigned int nbufs, int64_t offset, uv_fs_cb cb)
Definition:
fs.c:1872
uv_idle_stop
UV_EXTERN int uv_idle_stop(uv_idle_t *idle)
uv_buf_init
UV_EXTERN uv_buf_t uv_buf_init(char *base, unsigned int len)
Definition:
uv-common.c:157
uv_run
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
Definition:
core.c:365
uv_strerror
UV_EXTERN const char * uv_strerror(int err)
Definition:
uv-common.c:212
uv_default_loop
UV_EXTERN uv_loop_t * uv_default_loop(void)
Definition:
uv-common.c:763
uv_idle_start
UV_EXTERN int uv_idle_start(uv_idle_t *idle, uv_idle_cb cb)
uv_idle_init
UV_EXTERN int uv_idle_init(uv_loop_t *, uv_idle_t *idle)
subprojects
libuv-v1.40.0
docs
code
idle-compute
main.c
Generated by
1.9.1