Lely core libraries  2.3.4
file.h File Reference
#include <lely/io/io.h>
Include dependency graph for file.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  {
  IO_FILE_READ = 1 << 0, IO_FILE_WRITE = 1 << 1, IO_FILE_APPEND = 1 << 2, IO_FILE_CREATE = 1 << 3,
  IO_FILE_NO_EXIST = 1 << 4, IO_FILE_TRUNCATE = 1 << 5
}
 
enum  { IO_SEEK_BEGIN, IO_SEEK_CURRENT, IO_SEEK_END }
 

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 header file is part of the I/O library; it contains the regular file declarations.

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.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
IO_FILE_READ 

Open a file for reading.

IO_FILE_WRITE 

Open a file for writing.

IO_FILE_APPEND 

Append data to the end of the file.

IO_FILE_CREATE 

Create a new file if it does not exists.

IO_FILE_NO_EXIST 

Fail if the file already exists (ignored unless IO_FILE_CREATE is set).

IO_FILE_TRUNCATE 

Truncate an existing file (ignored if IO_FILE_NO_EXIST is set).

Definition at line 27 of file file.h.

◆ anonymous enum

anonymous enum
Enumerator
IO_SEEK_BEGIN 

A seek operation with respect to the beginning of a file.

IO_SEEK_CURRENT 

A seek operation with respect to the current offset in a file.

IO_SEEK_END 

A seek operation with respect to the end of a file.

Definition at line 45 of file file.h.

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 81 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 185 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 202 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 219 of file file.c.