WARNING: The online documentation has moved to https://docs.pjsip.org.

Visit the new documentation at https://docs.pjsip.org:

BLOG | DOCUMENTATION | GITHUB

Home --> Documentations --> PJLIB Reference

Enumerations

enum  pj_file_access { PJ_O_RDONLY = 0x1101, PJ_O_WRONLY = 0x1102, PJ_O_RDWR = 0x1103, PJ_O_APPEND = 0x1108 }
enum  pj_file_seek_type { PJ_SEEK_SET = 0x1201, PJ_SEEK_CUR = 0x1202, PJ_SEEK_END = 0x1203 }

Functions

pj_status_t pj_file_open (pj_pool_t *pool, const char *pathname, unsigned flags, pj_oshandle_t *fd)
pj_status_t pj_file_close (pj_oshandle_t fd)
pj_status_t pj_file_write (pj_oshandle_t fd, const void *data, pj_ssize_t *size)
pj_status_t pj_file_read (pj_oshandle_t fd, void *data, pj_ssize_t *size)
pj_status_t pj_file_setpos (pj_oshandle_t fd, pj_off_t offset, enum pj_file_seek_type whence)
pj_status_t pj_file_getpos (pj_oshandle_t fd, pj_off_t *pos)
pj_status_t pj_file_flush (pj_oshandle_t fd)

Detailed Description

This file contains functionalities to perform file I/O. The file I/O can be implemented with various back-end, either using native file API or ANSI stream.

Size Limits

There may be limitation on the size that can be handled by the pj_file_setpos() or pj_file_getpos() functions. The API itself uses 64-bit integer for the file offset/position (where available); however some backends (such as ANSI) may only support signed 32-bit offset resolution.

Reading and writing operation uses signed 32-bit integer to indicate the size.


Enumeration Type Documentation

These enumerations are used when opening file. Values PJ_O_RDONLY, PJ_O_WRONLY, and PJ_O_RDWR are mutually exclusive. Value PJ_O_APPEND can only be used when the file is opened for writing.

Enumerator:
PJ_O_RDONLY 

Open file for reading.

PJ_O_WRONLY 

Open file for writing.

PJ_O_RDWR 

Open file for reading and writing. File will be truncated.

PJ_O_APPEND 

Append to existing file.

The seek directive when setting the file position with pj_file_setpos.

Enumerator:
PJ_SEEK_SET 

Offset from beginning of the file.

PJ_SEEK_CUR 

Offset from current position.

PJ_SEEK_END 

Size of the file plus offset.


Function Documentation

pj_status_t pj_file_close ( pj_oshandle_t  fd  ) 

Close an opened file descriptor.

Parameters:
fd The file descriptor.
Returns:
PJ_SUCCESS or the appropriate error code on error.
pj_status_t pj_file_flush ( pj_oshandle_t  fd  ) 

Flush file buffers.

Parameters:
fd The file descriptor.
Returns:
PJ_SUCCESS or the appropriate error code on error.
pj_status_t pj_file_getpos ( pj_oshandle_t  fd,
pj_off_t pos 
)

Get current file position.

Parameters:
fd The file descriptor.
pos On return contains the file position as measured from the beginning of the file.
Returns:
PJ_SUCCESS or the appropriate error code on error.
pj_status_t pj_file_open ( pj_pool_t pool,
const char *  pathname,
unsigned  flags,
pj_oshandle_t fd 
)

Open the file as specified in pathname with the specified mode, and return the handle in fd. All files will be opened as binary.

Parameters:
pool Pool to allocate memory for the new file descriptor.
pathname The file name to open.
flags Open flags, which is bitmask combination of pj_file_access enum. The flag must be either PJ_O_RDONLY, PJ_O_WRONLY, or PJ_O_RDWR. When file writing is specified, existing file will be truncated unless PJ_O_APPEND is specified.
fd The returned descriptor.
Returns:
PJ_SUCCESS or the appropriate error code on error.
pj_status_t pj_file_read ( pj_oshandle_t  fd,
void *  data,
pj_ssize_t size 
)

Read data from the specified file. When end-of-file condition is set, this function will return PJ_SUCCESS but the size will contain zero.

Parameters:
fd The file descriptor.
data Pointer to buffer to receive the data.
size On input, specifies the maximum number of data to read from the file. On output, it contains the size of data actually read from the file. It will contain zero when EOF occurs.
Returns:
PJ_SUCCESS or the appropriate error code on error. When EOF occurs, the return is PJ_SUCCESS but size will report zero.
pj_status_t pj_file_setpos ( pj_oshandle_t  fd,
pj_off_t  offset,
enum pj_file_seek_type  whence 
)

Set file position to new offset according to directive whence.

Parameters:
fd The file descriptor.
offset The new file position to set.
whence The directive.
Returns:
PJ_SUCCESS or the appropriate error code on error.
pj_status_t pj_file_write ( pj_oshandle_t  fd,
const void *  data,
pj_ssize_t size 
)

Write data with the specified size to an opened file.

Parameters:
fd The file descriptor.
data Data to be written to the file.
size On input, specifies the size of data to be written. On return, it contains the number of data actually written to the file.
Returns:
PJ_SUCCESS or the appropriate error code on error.

 


PJLIB Open Source, high performance, small footprint, and very very portable framework
Copyright (C) 2006-2009 Teluu Inc.