2015-09-16 16:34:49 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "uv.h"
|
|
|
|
|
|
|
|
|
|
#include "scheduler.h"
|
|
|
|
|
#include "vm.h"
|
|
|
|
|
#include "wren.h"
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
// Called by libuv when the stat call for size completes.
|
|
|
|
|
static void sizeCallback(uv_fs_t* request)
|
|
|
|
|
{
|
|
|
|
|
WrenValue* fiber = (WrenValue*)request->data;
|
|
|
|
|
|
|
|
|
|
if (request->result != 0)
|
|
|
|
|
{
|
|
|
|
|
schedulerResumeString(fiber, uv_strerror((int)request->result));
|
|
|
|
|
uv_fs_req_cleanup(request);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double size = (double)request->statbuf.st_size;
|
|
|
|
|
uv_fs_req_cleanup(request);
|
|
|
|
|
|
|
|
|
|
schedulerResumeDouble(fiber, size);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 16:58:39 +02:00
|
|
|
void fileStartSize(WrenVM* vm)
|
2015-09-16 16:34:49 +02:00
|
|
|
{
|
|
|
|
|
const char* path = wrenGetArgumentString(vm, 1);
|
|
|
|
|
WrenValue* fiber = wrenGetArgumentValue(vm, 2);
|
|
|
|
|
|
|
|
|
|
// Store the fiber to resume when the request completes.
|
|
|
|
|
uv_fs_t* request = (uv_fs_t*)malloc(sizeof(uv_fs_t));
|
|
|
|
|
request->data = fiber;
|
|
|
|
|
|
|
|
|
|
uv_fs_stat(getLoop(), request, path, sizeCallback);
|
|
|
|
|
}
|