Created
December 29, 2014 13:36
-
-
Save heapwolf/b3099eccf0a775bcd4b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uv_fs_t stat_req; | |
uv_fs_t open_req; | |
uv_fs_t read_req; | |
uv_fs_t close_req; | |
int statR = uv_fs_stat(UV_LOOP, &stat_req, path, NULL); | |
const uv_stat_t* stat = static_cast<const uv_stat_t*>(stat_req.ptr); | |
int fd = uv_fs_open(UV_LOOP, &open_req, path, opts.flags, opts.mode, NULL); | |
int const size = (int) stat->st_size; | |
int offset = 0; | |
uv_buf_t buf; | |
buf.base = (char *) malloc(size); | |
buf.len = size; | |
int readR = uv_fs_read(UV_LOOP, &read_req, fd, &buf, 1, offset, NULL); | |
int closeR = uv_fs_close(UV_LOOP, &close_req, fd, NULL); | |
// this is always true | |
cout << bool(buf.len == size && buf.len == readR && size == readR) << endl; | |
cout << bool(strcmp(s.c_str(), buf.base)) << endl; | |
uv_fs_req_cleanup(&stat_req); | |
uv_fs_req_cleanup(&read_req); | |
uv_fs_req_cleanup(&open_req); | |
uv_fs_req_cleanup(&close_req); | |
return buf; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The string
s
andbuf.base
are not always the same for some reason... but the stat'ssize
,buf.len
and number of bytes read byuv_fs_read
are always equal.