How to write a C function that is binding to open a file handle in RUST?

I have played with writing library bindings in Rust, and it’s not difficult. However, now, I’m stuck: I’m trying to write a binding for librsync, and it’s Some functions expect you to pass an open file handle (FILE * in C).

For primitive types, there is a direct way to pass them to C, (for pointers to primitive types And, to be clear, I know that libc crate implements fopen, which in turn gives me a mut FILE* (which will eventually do the job). However, I want to know if there is something in the Rust standard library that gives I pass a FILE* to librsync-maybe something similar to std::ffi::CString.

Of course you can use RawFd, transmute and use it to call libc::funcs::posix88::stdio::fdopen(_,mode). But it will be very non-portable.

I used to play with writing library bindings in Rust and it was not difficult. However, now, I am stuck: I am trying to write a binding for librsync, and some of its functions expect you to pass an open file handle ( FILE *) in C.

For primitive types, there is a direct way to pass them to C, (the same is true for pointers to primitive types). And, to be clear, I know libc crate implements fopen, which in turn gives me a mut FILE* (which will eventually do the job). However, I want to know if there is something in the Rust standard library to give me a FILE* to pass to librsync-maybe something like std::ffi::CString stuff.

Of course you can use RawFd, transmute and use it to call libc::funcs::posix88::stdio: fdopen(_,mode). But it will be very non-portable.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5353 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.