Index wasi args_get args_sizes_get clock_res_get clock_time_get environ_get environ_sizes_get fd_advise fd_allocate fd_close fd_datasync fd_fdstat_get fd_fdstat_set_flags fd_fdstat_set_rights fd_filestat_get fd_filestat_set_size fd_filestat_set_times fd_pread fd_prestat_dir_name fd_prestat_get fd_pwrite fd_read fd_readdir fd_renumber fd_seek fd_sync fd_tell fd_write file_stat_flags filestat iovec lookup_flags path_create_directory path_filestat_get path_filestat_set_times path_link path_open path_readlink path_remove_directory path_rename path_symlink path_unlink_file poll_oneoff proc_exit proc_raise random_get sched_yield sock_accept sock_recv sock_send sock_shutdown
Write to a file without adjusting its offset
fd_pwrite (
fd: i32The file descriptor of the file to write toiovs: i32A pointer to an array of iovec structures describing the buffers from which data will be readiovs_len: i32The number of vectors iovecs in the iovs arrayoffset: i32The offset indicating the position at which the data will be writtennwritten: i32A pointer to store the number of bytes written
) =>
error: i32 

The fd_pwrite() function is used to write data to a file identified by the provided file descriptor (fd) without modifying its offset. It takes an array of iovec structures describing the buffers from which data will be read, the number of vectors (iovs_len) in the iovec array, the offset indicating the position at which the data will be written, and a pointer to store the number of bytes written. The function writes the data to the file at the specified offset and returns the number of bytes written.

In POSIX systems, writing data to a file typically involves updating the file cursor, which determines the next position at which data will be written. However, the fd_pwrite() function provides a way to write data to a file without adjusting its offset. This can be useful in scenarios where applications need to write data at a specific location in a file without modifying the file cursor's state.

Note

The fd_pwrite() function allows writing data to a file identified by the file descriptor fd without adjusting its offset. It takes the file descriptor, an array of buffers from which data will be read, the number of vectors in the iovec array, the offset indicating the position at which the data will be written, and a pointer to store the number of bytes written. The function writes the data to the file at the specified offset without modifying the file cursor's state. It returns an error code to indicate the success or failure of the operation. If the data is successfully written to the file, it returns Errno::Success. Otherwise, it returns an appropriate error code.

Read More