static void read_cb(uv_fs_t* req) { int r; TUV_ASSERT(req == &read_req); TUV_ASSERT(req->fs_type == UV_FS_READ); TUV_ASSERT(req->result >= 0); /* FIXME(bnoordhuis) Check if requested size? */ read_cb_count++; uv_fs_req_cleanup(req); if (read_cb_count == 1) { TUV_ASSERT(strcmp(buf, test_buf) == 0); #if !defined(__NUTTX__) r = uv_fs_ftruncate(loop, &ftruncate_req, open_req1.result, 7, ftruncate_cb); #else /* cannot truncate on nuttx so just close the file */ r = uv_fs_close(loop, &close_req, open_req1.result, close_cb); #endif } else { #if !defined(__NUTTX__) TUV_ASSERT(strcmp(buf, "test-bu") == 0); #else TUV_ASSERT(strcmp(buf, test_buf) == 0); #endif r = uv_fs_close(loop, &close_req, open_req1.result, close_cb); } TUV_ASSERT(r == 0); }
/* * fs.ftruncate */ static int fs_ftruncate(lua_State* L) { FSR__SETUP int fd = luaL_checkint(L, 1); int64_t file_size = luaL_checklong(L, 2); FSR__SET_OPT_CB(3, on_fs_callback) uv_fs_ftruncate(loop, req, fd, file_size, cb); FSR__TEARDOWN }
static int lluv_file_truncate(lua_State *L){ const char *path = NULL; lluv_file_t *f = lluv_check_file(L, 1, LLUV_FLAG_OPEN); lluv_loop_t *loop = f->loop; int64_t len = lutil_checkint64(L, 2); int argc = 2; LLUV_PRE_FILE(); lua_pushvalue(L, 1); req->file_ref = luaL_ref(L, LLUV_LUA_REGISTRY); err = uv_fs_ftruncate(loop->handle, &req->req, f->handle, len, cb); LLUV_POST_FILE(); }
static void read_cb(uv_fs_t* req) { int r; ASSERT(req == &read_req); ASSERT(req->fs_type == UV_FS_READ); ASSERT(req->result != -1); read_cb_count++; uv_fs_req_cleanup(req); if (read_cb_count == 1) { ASSERT(strcmp(buf, test_buf) == 0); r = uv_fs_ftruncate(&ftruncate_req, open_req1.result, 7, ftruncate_cb); } else { ASSERT(strcmp(buf, "test-bu") == 0); r = uv_fs_close(&close_req, open_req1.result, close_cb); } }
static void read_cb(uv_fs_t* req) { int r; ASSERT(req == &read_req); ASSERT(req->fs_type == UV_FS_READ); ASSERT(req->result >= 0); /* FIXME(bnoordhuis) Check if requested size? */ read_cb_count++; uv_fs_req_cleanup(req); if (read_cb_count == 1) { ASSERT(strcmp(buf, test_buf) == 0); r = uv_fs_ftruncate(loop, &ftruncate_req, open_req1.result, 7, ftruncate_cb); } else { ASSERT(strcmp(buf, "test-bu") == 0); r = uv_fs_close(loop, &close_req, open_req1.result, close_cb); } ASSERT(r == 0); }
/* Truncates the file handle. */ static void truncatefh(MVMThreadContext *tc, MVMOSHandle *h, MVMint64 bytes) { MVMIOFileData *data = (MVMIOFileData *)h->body.data; uv_fs_t req; if(uv_fs_ftruncate(tc->loop, &req, data->fd, bytes, NULL) < 0 ) MVM_exception_throw_adhoc(tc, "Failed to truncate filehandle: %s", uv_strerror(req.result)); }