| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#include "config.h" |
| 22 |
|
| 23 |
#ifdef HAVE_UNISTD_H |
| 24 |
#include <unistd.h> |
| 25 |
#endif |
| 26 |
|
| 27 |
#include "dex-fd-private.h" |
| 28 |
|
| 29 |
#ifdef G_OS_WIN32 |
| 30 |
#include <io.h> |
| 31 |
#endif |
| 32 |
|
| 33 |
int |
| 34 |
dex_fd_peek (const DexFD *fd) |
| 35 |
{ |
| 36 |
if (fd == NULL) |
| 37 |
return -1; |
| 38 |
|
| 39 |
return *(int *)fd; |
| 40 |
} |
| 41 |
|
| 42 |
int |
| 43 |
dex_fd_steal (DexFD *fd) |
| 44 |
{ |
| 45 |
if (fd == NULL) |
| 46 |
return -1; |
| 47 |
|
| 48 |
return g_steal_fd ((int *)fd); |
| 49 |
} |
| 50 |
|
| 51 |
void |
| 52 |
dex_fd_free (DexFD *fd) |
| 53 |
{ |
| 54 |
int real = dex_fd_steal (fd); |
| 55 |
if (real != -1) |
| 56 |
close (real); |
| 57 |
g_free (fd); |
| 58 |
} |
| 59 |
|
| 60 |
DexFD * |
| 61 |
dex_fd_dup (const DexFD *fd) |
| 62 |
{ |
| 63 |
int real = dex_fd_peek (fd); |
| 64 |
|
| 65 |
if (real == -1) |
| 66 |
return NULL; |
| 67 |
|
| 68 |
real = dup (real); |
| 69 |
|
| 70 |
return g_memdup2 (&real, sizeof real); |
| 71 |
} |
| 72 |
|
| 73 |
G_DEFINE_BOXED_TYPE (DexFD, dex_fd, dex_fd_dup, dex_fd_free) |