foobar2000 SDK  2015-08-03
filehandle.cpp
Go to the documentation of this file.
1 #include "pfc.h"
2 
3 #ifndef _WIN32
4 #include <unistd.h>
5 #endif
6 
7 namespace pfc {
9  if (h == fileHandleInvalid) return;
10 #ifdef _WIN32
11  CloseHandle( h );
12 #else
13  close( h );
14 #endif
15 }
16 
18 #ifdef _WIN32
19  auto proc = GetCurrentProcess();
20  HANDLE out;
21  if (!DuplicateHandle ( proc, h, proc, &out, 0, FALSE, DUPLICATE_SAME_ACCESS )) return fileHandleInvalid;
22  return out;
23 #else
24  return dup( h );
25 #endif
26 }
27 
29  fileHandleClose( h );
30  clear();
31 }
32 
33 }
HANDLE fileHandle_t
Definition: filehandle.h:3
fileHandle_t h
Definition: filehandle.h:24
typedef HANDLE(WINAPI *pPowerCreateRequest_t)(__in void *Context)
fileHandle_t fileHandleDup(fileHandle_t h)
Definition: filehandle.cpp:17
const fileHandle_t fileHandleInvalid
Definition: filehandle.h:4
void fileHandleClose(fileHandle_t h)
Definition: filehandle.cpp:8