Mercurial > foo_out_sdl
diff foosdk/sdk/pfc/filehandle.cpp @ 1:20d02a178406 default tip
*: check in everything else
yay
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 05 Jan 2026 02:15:46 -0500 |
| parents | |
| children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/foosdk/sdk/pfc/filehandle.cpp Mon Jan 05 02:15:46 2026 -0500 @@ -0,0 +1,34 @@ +#include "pfc-lite.h" +#include "filehandle.h" + +#ifndef _WIN32 +#include <unistd.h> +#endif + +namespace pfc { +void fileHandleClose( fileHandle_t h ) noexcept { + if (h == fileHandleInvalid) return; +#ifdef _WIN32 + CloseHandle( h ); +#else + close( h ); +#endif +} + +fileHandle_t fileHandleDup( fileHandle_t h ) { +#ifdef _WIN32 + auto proc = GetCurrentProcess(); + HANDLE out; + if (!DuplicateHandle ( proc, h, proc, &out, 0, FALSE, DUPLICATE_SAME_ACCESS )) return fileHandleInvalid; + return out; +#else + return dup( h ); +#endif +} + +void fileHandle::close() noexcept { + fileHandleClose( h ); + clear(); +} + +} \ No newline at end of file
