#include <unistd.h>
#include <sys/time.h>
-#include <pthread.h>
+#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#endif
#include "os.hpp"
-#include "os_path.hpp"
+#include "os_string.hpp"
namespace os {
-static pthread_mutex_t
-mutex = PTHREAD_MUTEX_INITIALIZER;
-
-
-void
-acquireMutex(void)
-{
- pthread_mutex_lock(&mutex);
-}
-
-
-void
-releaseMutex(void)
-{
- pthread_mutex_unlock(&mutex);
-}
-
-
-Path
+String
getProcessName(void)
{
- Path path;
+ String path;
size_t size = PATH_MAX;
char *buf = path.buf(size);
return path;
}
-Path
+String
getCurrentDir(void)
{
- Path path;
+ String path;
size_t size = PATH_MAX;
char *buf = path.buf(size);
}
bool
-Path::exists(void) const
+String::exists(void) const
{
struct stat st;
int err;
return true;
}
+int execute(char * const * args)
+{
+ pid_t pid = fork();
+ if (pid == 0) {
+ // child
+ execvp(args[0], args);
+ fprintf(stderr, "error: failed to execute %s\n", args[0]);
+ exit(-1);
+ } else {
+ // parent
+ if (pid == -1) {
+ fprintf(stderr, "error: failed to fork\n");
+ return -1;
+ }
+ int status = -1;
+ waitpid(pid, &status, 0);
+ return status;
+ }
+}
+
void
log(const char *format, ...)
{