Rizin
unix-like reverse engineering framework and cli tools
main.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <fcntl.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include <stdlib.h>
6 
7 #include <uv.h>
8 
9 typedef struct {
11  uv_buf_t buf;
12 } write_req_t;
13 
18 
19 void alloc_buffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) {
20  *buf = uv_buf_init((char*) malloc(suggested_size), suggested_size);
21 }
22 
24  write_req_t *wr = (write_req_t*) req;
25  free(wr->buf.base);
26  free(wr);
27 }
28 
31 }
32 
35 }
36 
39  req->buf = uv_buf_init((char*) malloc(size), size);
40  memcpy(req->buf.base, buf.base, size);
41  uv_write((uv_write_t*) req, (uv_stream_t*)dest, &req->buf, 1, cb);
42 }
43 
45  if (nread < 0){
46  if (nread == UV_EOF){
47  // end of file
51  }
52  } else if (nread > 0) {
55  }
56 
57  // OK to free buffer as write_data copies it.
58  if (buf->base)
59  free(buf->base);
60 }
61 
62 int main(int argc, char **argv) {
64 
67 
70 
71  uv_fs_t file_req;
72  int fd = uv_fs_open(loop, &file_req, argv[1], O_CREAT | O_RDWR, 0644, NULL);
75 
77 
79  return 0;
80 }
static mcore_handle handle
Definition: asm_mcore.c:8
#define NULL
Definition: cris-opc.c:27
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
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void uLong size
Definition: ioapi.h:138
voidpf stream
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
int main(int argc, const char **argv)
Definition: main.c:340
void * malloc(size_t size)
Definition: malloc.c:123
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
static const char struct stat static buf struct stat static buf static vhangup int status
Definition: sflib.h:145
char * dest
Definition: lz4.h:697
#define O_CREAT
Definition: sftypes.h:489
#define O_RDWR
Definition: sftypes.h:488
int ssize_t
Definition: sftypes.h:39
Definition: unix.h:123
char * base
Definition: unix.h:124
Definition: uv.h:1306
Definition: uv.h:1780
Definition: uv.h:767
Definition: uv.h:525
uv_buf_t buf
Definition: worker.c:13
uv_loop_t * loop
Definition: main.c:7
void alloc_buffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf)
Definition: main.c:8
void free_write_req(uv_write_t *req)
Definition: main.c:19
uv_pipe_t stdin_pipe
Definition: main.c:15
void on_stdout_write(uv_write_t *req, int status)
Definition: main.c:29
void write_data(uv_stream_t *dest, size_t size, uv_buf_t buf, uv_write_cb cb)
Definition: main.c:37
void on_file_write(uv_write_t *req, int status)
Definition: main.c:33
uv_pipe_t file_pipe
Definition: main.c:17
void read_stdin(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
Definition: main.c:44
uv_pipe_t stdout_pipe
Definition: main.c:16
UV_EXTERN int uv_fs_open(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, int mode, uv_fs_cb cb)
Definition: fs.c:1858
@ UV_RUN_DEFAULT
Definition: uv.h:255
void(* uv_write_cb)(uv_write_t *req, int status)
Definition: uv.h:315
UV_EXTERN int uv_write(uv_write_t *req, uv_stream_t *handle, const uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb)
Definition: stream.c:1492
UV_EXTERN uv_buf_t uv_buf_init(char *base, unsigned int len)
Definition: uv-common.c:157
UV_EXTERN int uv_read_start(uv_stream_t *, uv_alloc_cb alloc_cb, uv_read_cb read_cb)
Definition: stream.c:1555
UV_EXTERN int uv_pipe_init(uv_loop_t *, uv_pipe_t *handle, int ipc)
Definition: pipe.c:33
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
Definition: core.c:365
UV_EXTERN void uv_close(uv_handle_t *handle, uv_close_cb close_cb)
Definition: core.c:108
UV_EXTERN uv_loop_t * uv_default_loop(void)
Definition: uv-common.c:763
UV_EXTERN int uv_pipe_open(uv_pipe_t *, uv_file file)
Definition: pipe.c:137
static const z80_opcode fd[]
Definition: z80_tab.h:997
static const char * cb[]
Definition: z80_tab.h:176