-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patheject_idb.cpp
More file actions
53 lines (47 loc) · 1.2 KB
/
eject_idb.cpp
File metadata and controls
53 lines (47 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <cstdio>
#include <cstring>
#ifdef _WIN32
#include <windows.h>
#elif __APPLE__ || __linux__
#include <fcntl.h>
#include <sys/stat.h>
#include <semaphore.h>
#else
#error "Platform not supported"
#endif
#include "utils.hpp"
int main(int argc, char* argv[])
{
if (argc < 2)
{
printf("Usage: %s <IDB file path>\n", argv[0]);
return 1;
}
#ifdef __TESTING__
char input[100]; // buffer for user input
printf("eject_idb waiting...press ENTER to continue\n");
fgets(input, sizeof(input), stdin); // read a line, user must press enter
#endif
char sem_name[64];
make_semaphore_name(argv[1], sem_name, sizeof(sem_name));
do
{
#ifdef _WIN32
HANDLE hSemaphore = OpenSemaphoreA(SEMAPHORE_MODIFY_STATE, FALSE, sem_name);
if (hSemaphore == NULL)
break;
ReleaseSemaphore(hSemaphore, 1, NULL);
CloseHandle(hSemaphore);
#else
sem_t* sem = sem_open(sem_name, 0);
if (sem == SEM_FAILED)
break;
sem_post(sem);
sem_close(sem);
#endif
printf("Ejected %s\n", argv[1]);
return 0;
} while (false);
printf("Failed to eject %s\n", argv[1]);
return 1;
}