Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
Functions
file_wrappers.h File Reference
#include <wireshark.h>
#include "wtap.h"
#include <wsutil/file_util.h>

Go to the source code of this file.

Functions

FILE_T file_open (const char *path)
 
FILE_T file_fdopen (int fildes)
 
void file_set_random_access (FILE_T stream, bool random_flag, GPtrArray *seek)
 
WS_DLL_PUBLIC int64_t file_seek (FILE_T stream, int64_t offset, int whence, int *err)
 Seek to a position in the file.
 
WS_DLL_PUBLIC int64_t file_tell (FILE_T stream)
 Get current position in the file.
 
int64_t file_tell_raw (FILE_T stream)
 
int file_fstat (FILE_T stream, ws_statb64 *statb, int *err)
 
WS_DLL_PUBLIC bool file_iscompressed (FILE_T stream)
 Check if file is compressed.
 
WS_DLL_PUBLIC int file_read (void *buf, unsigned int count, FILE_T file)
 Read bytes from a file.
 
WS_DLL_PUBLIC int file_peekc (FILE_T stream)
 Peek the next byte from the file without advancing the position.
 
WS_DLL_PUBLIC int file_getc (FILE_T stream)
 Read the next byte from the file.
 
WS_DLL_PUBLIC char * file_gets (char *buf, int len, FILE_T stream)
 Read a line from the file.
 
WS_DLL_PUBLIC char * file_getsp (char *buf, int len, FILE_T stream)
 Read a line from the file, skipping leading whitespace.
 
WS_DLL_PUBLIC bool file_eof (FILE_T stream)
 Check for end-of-file.
 
WS_DLL_PUBLIC int file_error (FILE_T fh, char **err_info)
 Check for file error.
 
void file_clearerr (FILE_T stream)
 
void file_fdclose (FILE_T file)
 
bool file_fdreopen (FILE_T file, const char *path)
 
void file_close (FILE_T file)
 

Detailed Description

Wiretap Library Copyright (c) 1998 by Gilbert Ramirez gram@.nosp@m.alum.nosp@m.ni.ri.nosp@m.ce.e.nosp@m.du

SPDX-License-Identifier: GPL-2.0-or-later

Function Documentation

◆ file_eof()

WS_DLL_PUBLIC bool file_eof ( FILE_T  stream)

Check for end-of-file.

Returns true if EOF has been reached on the stream.

Parameters
streamFile handle.
Returns
true if EOF, false otherwise.

◆ file_error()

WS_DLL_PUBLIC int file_error ( FILE_T  fh,
char **  err_info 
)

Check for file error.

Returns the error status and optionally sets an error message.

Parameters
fhFile handle.
err_infoOptional pointer to error message string.
Returns
Error code, or 0 if no error.

◆ file_getc()

WS_DLL_PUBLIC int file_getc ( FILE_T  stream)

Read the next byte from the file.

Advances the file position by one.

Parameters
streamFile handle.
Returns
Byte value or EOF.

◆ file_gets()

WS_DLL_PUBLIC char * file_gets ( char *  buf,
int  len,
FILE_T  stream 
)

Read a line from the file.

Reads up to len - 1 characters into buf, stopping at newline or EOF.

Parameters
bufDestination buffer.
lenBuffer size.
streamFile handle.
Returns
buf on success, or NULL on error or EOF.

◆ file_getsp()

WS_DLL_PUBLIC char * file_getsp ( char *  buf,
int  len,
FILE_T  stream 
)

Read a line from the file, skipping leading whitespace.

Similar to file_gets(), but trims leading spaces before reading.

Parameters
bufDestination buffer.
lenBuffer size.
streamFile handle.
Returns
buf on success, or NULL on error or EOF.

◆ file_iscompressed()

WS_DLL_PUBLIC bool file_iscompressed ( FILE_T  stream)

Check if file is compressed.

Returns true for compressed formats.

Parameters
streamFile handle.
Returns
true if compressed; false otherwise.

◆ file_peekc()

WS_DLL_PUBLIC int file_peekc ( FILE_T  stream)

Peek the next byte from the file without advancing the position.

Returns the next byte in the stream or EOF.

Parameters
streamFile handle.
Returns
Byte value or EOF.

◆ file_read()

WS_DLL_PUBLIC int file_read ( void *  buf,
unsigned int  count,
FILE_T  file 
)

Read bytes from a file.

Reads up to count bytes into buf from the given file stream.

Parameters
bufDestination buffer.
countNumber of bytes to read.
fileFile handle.
Returns
Number of bytes read, or -1 on error.

◆ file_seek()

WS_DLL_PUBLIC int64_t file_seek ( FILE_T  stream,
int64_t  offset,
int  whence,
int *  err 
)

Seek to a position in the file.

Supports large offsets and returns error codes.

Parameters
streamFile handle.
offsetByte offset.
whenceSEEK_SET, SEEK_CUR, or SEEK_END.
errOptional error code output.
Returns
New position or -1 on failure.

◆ file_tell()

WS_DLL_PUBLIC int64_t file_tell ( FILE_T  stream)

Get current position in the file.

Returns logical position, accounting for buffering.

Parameters
streamFile handle.
Returns
Current offset or -1 on failure.