-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmystdlib.h
executable file
·97 lines (83 loc) · 2.13 KB
/
mystdlib.h
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Gowtham Kudupudi 26/03/2013
* MIT License
*/
#ifndef MYSTDLIB_H
#define MYSTDLIB_H
#include <sys/types.h>
#include <string>
#include <signal.h>
#include <list>
#include <map>
#include <iostream>
#include <fstream>
//#if !defined(__mode_t)
# if defined(__NEED_mode_t)
typedef mode_t __mode_t;
# endif
//#endif
#define NELEMS(x) (sizeof(x) / sizeof(x[0]))
#if defined(_WIN32) || defined(_WIN64)
#include <direct.h>
#define GetCurrentDir _getcwd
#else
#include <unistd.h>
#define GetCurrentDir getcwd
#endif
#if defined(__linux__)
void initTermios(int echo);
void resetTermios(void);
char getch_(int echo);
char getch(void);
char getche(void);
int copyfile(std::string src, std::string dst);
std::string getCurrentDir();
std::string getMachineName();
int rmmydir(std::string dirn);
std::string inputPass();
std::string inputText();
std::string getStdoutFromCommand(std::string cmd);
std::string get_command_line(pid_t pid);
int poke(std::string ip);
int getIp();
std::string GetPrimaryIp();
std::string get_fd_contents(int fd);
char const * sperm(__mode_t mode);
extern int child_exit_status;
class spawn {
private:
int cpstdinp[2];
int cpstdoutp[2];
int cpstderrp[2];
public:
static bool processCleaned;
static void defaultOnStopHandler(spawn* process);
pid_t cpid = 0;
int cpstdin = -1;
int cpstdout = -1;
int cpstderr = -1;
int childExitStatus = 0;
std::string cmd = "";
std::string cmdName = "";
void (*onStopHandler)(spawn*);
spawn();
spawn (std::string command, bool daemon = false,
void (*onStopHandler)(spawn*) = NULL, bool freeChild = false,
bool block = false
);
int getChildExitStatus();
int pkill(int signal = SIGTERM);
};
extern std::map<pid_t, spawn*> processMap;
#endif /* __linux__ */
struct cfout_ : std::ofstream {
cfout_ (const std::string& fileName) : std::ofstream(fileName) {};
};
template <typename Input_>
cfout_& operator<<(cfout_& strm, const Input_& var) {
std::cout << var;
static_cast<std::ofstream&>(strm) << var;
return strm;
};
std::string random_alphnuma_string (int size = 16);
#endif /* MYSTDLIB_H */