I am trying to learn how to use libuv. I am on a mac OS X and have the library downloaded and installed. I can compile and run small test programs one only starts a callback
You state that the prototype for the function uv_fs_open
is
int uv_fs_open(uv_loop_t* loop,
uv_fs_t* req,
const char* path,
int flags,
int mode,
uv_fs_cb cb)
Note that the type of the second argument is uv_fs_t*
. So when you declare open-rec
as
uv_fs_t open_req;
And then call uv_fs_open()
with
uv_fs_open(uv_default_loop(), &open_req, argv[1], O_RDONLY, 0, on_open);
the second argument (&open_req
) takes the address of open_req
and creates the required pointer. This should work just fine. However, from your original error message, I think you did not post all of the relevant code. Let's look at this error message:
invalid conversion from ‘void (*)(uv_fs_t)’ to ‘void (*)(uv_fs_t*)’
This states that the compiler expects a pointer to a function which returns void and takes a single parameter which is a pointer to a uv_fs_t
. On the other hand, you are providing a pointer to a function which returns void and takes a single parameter of type uv_fs_t
(i.e. not a pointer to uv_fs_t
).
This suggests that open_req
is a function (or a pointer to a function). In order to help you further, please edit your original question with the declaration of this function as well as how you initialize the open_req
variable if it is a pointer to a function rather than the name of the function itself.
Edit:
After a second look at your question, open_req
most likely doesn't cause the original error. You should change your code back to the way it was originally.
On the other hand, on_open
very likely causes the problem. You declare this function with the prototype
void on_open(uv_fs_t);
but the first line of the definition is
void on_open(uv_fs_t *req)
Remove the *
from the first line of the function definition and see what happens.