JX Application Framework
Loading...
Searching...
No Matches
Functions
jFStreamUtil_UNIX.cpp File Reference
#include "jFStreamUtil.h"
#include "JString.h"
#include <fcntl.h>
#include <unistd.h>
#include "jAssert.h"
Include dependency graph for jFStreamUtil_UNIX.cpp:

Functions

std::fstream * JSetFStreamLength (const JString &fileName, std::fstream &originalStream, const JSize newLength, const JFStreamOpenMode io_mode)
 

Function Documentation

◆ JSetFStreamLength()

std::fstream * JSetFStreamLength ( const JString fileName,
std::fstream &  originalStream,
const JSize  newLength,
const JFStreamOpenMode  io_mode 
)

Sets the length of the file associated with originalStream.

The only efficient way is to use ftruncate(), which requires a file descriptor. Since we can't get this from the stream, we require the file name. Once we operate on the descriptor, the stream will be hopelessly confused, so we have to close it first. This is why we return a jnew one afterwards.

The caller is responsible for deleting originalStream.