game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
PipeHandle Class Reference

RAII wrapper for FILE* from popen(). More...

#include <file_handle.h>

Public Member Functions

 PipeHandle (const char *command, const char *mode)
 Open pipe for command execution.
 PipeHandle (const PipeHandle &)=delete
 PipeHandle (const std::string &command, const char *mode)
 PipeHandle (PipeHandle &&other) noexcept
 ~PipeHandle ()
 Destructor - automatically closes pipe.
int close ()
 Close the pipe early and return pclose's exit status.
FILE * get () const
 Get raw FILE* pointer.
bool isOpen () const
 Check if pipe is open.
 operator bool () const
 Explicit bool conversion for easy checking.
PipeHandle & operator= (const PipeHandle &)=delete
PipeHandle & operator= (PipeHandle &&other) noexcept
FILE * release ()
 Release ownership of FILE* without closing.

Detailed Description

RAII wrapper for FILE* from popen().

Automatically closes pipe handle on destruction, preventing resource leaks. Non-copyable but movable.

Definition at line 155 of file file_handle.h.

Constructor & Destructor Documentation

◆ PipeHandle() [1/4]

PipeHandle::PipeHandle ( const char * command,
const char * mode )
inline

Open pipe for command execution.

Parameters
commandShell command to execute
modePipe mode ("r" for reading output, "w" for writing input)

Definition at line 163 of file file_handle.h.

Referenced by PipeHandle(), PipeHandle(), operator=(), and operator=().

◆ PipeHandle() [2/4]

PipeHandle::PipeHandle ( const std::string & command,
const char * mode )
inline

Definition at line 165 of file file_handle.h.

◆ ~PipeHandle()

PipeHandle::~PipeHandle ( )
inline

Destructor - automatically closes pipe.

Definition at line 172 of file file_handle.h.

◆ PipeHandle() [3/4]

PipeHandle::PipeHandle ( const PipeHandle & )
delete

References PipeHandle().

◆ PipeHandle() [4/4]

PipeHandle::PipeHandle ( PipeHandle && other)
inlinenoexcept

Definition at line 186 of file file_handle.h.

References PipeHandle().

Member Function Documentation

◆ close()

int PipeHandle::close ( )
inline

Close the pipe early and return pclose's exit status.

Equivalent to letting the destructor run, except the caller gets the wait-status word back (the same value pclose() returns: a wait(2)-style status on success, or -1 on error). Use this when you need to distinguish "command succeeded" from "command crashed / exited non-zero" — the destructor swallows that info. Repeated close() calls are no-ops; the destructor won't double-close.

Inspect the return value with the standard W* macros, e.g.: const int s = pipe.close(); if (s == -1 || (WIFEXITED(s) && WEXITSTATUS(s) != 0)) ...

Returns
pclose() return value, or 0 if pipe was already closed / never opened

Definition at line 239 of file file_handle.h.

Referenced by PrefixSnapshotService::importSnapshot().

◆ get()

◆ isOpen()

bool PipeHandle::isOpen ( ) const
inline

Check if pipe is open.

Returns
true if pipe handle is valid

Definition at line 218 of file file_handle.h.

Referenced by operator bool().

◆ operator bool()

PipeHandle::operator bool ( ) const
inlineexplicit

Explicit bool conversion for easy checking.

Definition at line 251 of file file_handle.h.

References isOpen().

◆ operator=() [1/2]

PipeHandle & PipeHandle::operator= ( const PipeHandle & )
delete

References PipeHandle().

◆ operator=() [2/2]

PipeHandle & PipeHandle::operator= ( PipeHandle && other)
inlinenoexcept

Definition at line 191 of file file_handle.h.

References PipeHandle().

◆ release()

FILE * PipeHandle::release ( )
inline

Release ownership of FILE* without closing.

Returns
FILE* pointer (caller must close with pclose)

Definition at line 260 of file file_handle.h.

Referenced by ProcessExecutor::executeWithOutput().


The documentation for this class was generated from the following file: