Add process searching

This commit is contained in:
topjohnwu
2017-04-07 06:21:20 +08:00
parent 3a7e782c07
commit b94227efc9
3 changed files with 103 additions and 1 deletions

View File

@ -12,6 +12,8 @@
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <dirent.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
@ -60,7 +62,6 @@ ssize_t xxread(int fd, void *buf, size_t count) {
int xpipe(int pipefd[2]) {
if (pipe(pipefd) == -1) {
PLOGE("pipe");
exit(1);
}
return 0;
}
@ -72,3 +73,20 @@ int xsetns(int fd, int nstype) {
return 0;
}
DIR *xopendir(const char *name) {
DIR *d = opendir(name);
if (d == NULL) {
PLOGE("opendir");
}
return d;
}
struct dirent *xreaddir(DIR *dirp) {
errno = 0;
struct dirent *e = readdir(dirp);
if (errno && e == NULL) {
PLOGE("readdir");
}
return e;
}