Lely core libraries  2.2.5
file.c File Reference

This file is part of the I/O library; it contains the implementation of the regular file functions. More...

#include "default.h"
#include "io.h"
#include <lely/io/file.h>
#include <assert.h>
Include dependency graph for file.c:

Go to the source code of this file.

Data Structures

struct  file
 A regular file handle. More...
 

Functions

io_handle_t io_open_file (const char *path, int flags)
 Opens a regular file. More...
 
io_off_t io_seek (io_handle_t handle, io_off_t offset, int whence)
 Moves the current read/write offset of an open file. More...
 
ssize_t io_pread (io_handle_t handle, void *buf, size_t nbytes, io_off_t offset)
 Performs a read operation at the specified offset, without updating the file pointer. More...
 
ssize_t io_pwrite (io_handle_t handle, const void *buf, size_t nbytes, io_off_t offset)
 Performs a write operation at the specified offset, without updating the file pointer. More...
 

Detailed Description

This file is part of the I/O library; it contains the implementation of the regular file functions.

See also
lely/io/file.h
Author
J. S. Seldenthuis jseld.nosp@m.enth.nosp@m.uis@l.nosp@m.ely..nosp@m.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition in file file.c.

Function Documentation

◆ io_open_file()

io_handle_t io_open_file ( const char *  path,
int  flags 
)

Opens a regular file.

Parameters
paththe path name of the file.
flagsany combination of IO_FILE_READ, IO_FILE_WRITE, IO_FILE_APPEND, IO_FILE_CREATE, IO_FILE_NO_EXIST and IO_FILE_TRUNCATE.
Returns
a I/O device handle, or IO_HANDLE_ERROR on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 77 of file file.c.

◆ io_seek()

io_off_t io_seek ( io_handle_t  handle,
io_off_t  offset,
int  whence 
)

Moves the current read/write offset of an open file.

Parameters
handlea valid file device handle.
offsetthe desired offset (in bytes) with respect to the beginning of the file (if whence == IO_SEEK_BEGIN), the current offset (if whence == IO_SEEK_CURRENT) or the end of the file (if whence == IO_SEEK_END).
whenceone of IO_SEEK_BEGIN, IO_SEEK_CURRENT or IO_SEEK_END.
Returns
the current offset with respect to the beginning of the file, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 181 of file file.c.

◆ io_pread()

ssize_t io_pread ( io_handle_t  handle,
void *  buf,
size_t  nbytes,
io_off_t  offset 
)

Performs a read operation at the specified offset, without updating the file pointer.

Parameters
handlea valid file device handle.
bufa pointer to the destination buffer.
nbytesthe number of bytes to read.
offsetthe offset (in bytes) at which to start reading.
Returns
the number of bytes read on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 198 of file file.c.

◆ io_pwrite()

ssize_t io_pwrite ( io_handle_t  handle,
const void *  buf,
size_t  nbytes,
io_off_t  offset 
)

Performs a write operation at the specified offset, without updating the file pointer.

Parameters
handlea valid file device handle.
bufa pointer to the source buffer.
nbytesthe number of bytes to write.
offsetthe offset (in bytes) at which to start writing.
Returns
the number of bytes written on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 215 of file file.c.