libobs/util: Remove dup. code, add os_opendir
Just use platform-nix.c code for general stuff that mac is compliant with, and put a define around everything else. Take that code out of platform-cocoa.m. Added os_opendir, os_readdir, and os_closedir to be able to query available files within a directory.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Ruwen Hahn <palana@stunned.de>
|
||||
* Copyright (c) 2013-2014 Ruwen Hahn <palana@stunned.de>
|
||||
* Hugh "Jim" Bailey <obs.jim@gmail.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -22,72 +23,12 @@
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <CoreServices/CoreServices.h>
|
||||
#include <mach/mach.h>
|
||||
#include <mach/mach_time.h>
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
void *os_dlopen(const char *path)
|
||||
{
|
||||
struct dstr dylib_name;
|
||||
|
||||
if (!path)
|
||||
return NULL;
|
||||
|
||||
dstr_init_copy(&dylib_name, path);
|
||||
if (!dstr_find(&dylib_name, ".so"))
|
||||
dstr_cat(&dylib_name, ".so");
|
||||
|
||||
void *res = dlopen(dylib_name.array, RTLD_LAZY);
|
||||
if (!res)
|
||||
blog(LOG_ERROR, "os_dlopen(%s->%s): %s\n",
|
||||
path, dylib_name.array, dlerror());
|
||||
|
||||
dstr_free(&dylib_name);
|
||||
return res;
|
||||
}
|
||||
|
||||
void *os_dlsym(void *module, const char *func)
|
||||
{
|
||||
return dlsym(module, func);
|
||||
}
|
||||
|
||||
void os_dlclose(void *module)
|
||||
{
|
||||
dlclose(module);
|
||||
}
|
||||
|
||||
bool os_sleepto_ns(uint64_t time_target)
|
||||
{
|
||||
uint64_t current = os_gettime_ns();
|
||||
if (time_target < current)
|
||||
return false;
|
||||
|
||||
time_target -= current;
|
||||
|
||||
struct timespec req, remain;
|
||||
memset(&req, 0, sizeof(req));
|
||||
memset(&remain, 0, sizeof(remain));
|
||||
req.tv_sec = time_target/1000000000;
|
||||
req.tv_nsec = time_target%1000000000;
|
||||
|
||||
while (nanosleep(&req, &remain)) {
|
||||
req = remain;
|
||||
memset(&remain, 0, sizeof(remain));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void os_sleep_ms(uint32_t duration)
|
||||
{
|
||||
usleep(duration*1000);
|
||||
}
|
||||
|
||||
|
||||
/* clock function selection taken from libc++ */
|
||||
static uint64_t ns_time_simple()
|
||||
{
|
||||
@@ -152,19 +93,3 @@ char *os_get_config_path(const char *name)
|
||||
dstr_cat(&path, name);
|
||||
return path.array;
|
||||
}
|
||||
|
||||
bool os_file_exists(const char *path)
|
||||
{
|
||||
return access(path, F_OK) == 0;
|
||||
}
|
||||
|
||||
int os_mkdir(const char *path)
|
||||
{
|
||||
if(!mkdir(path, 0777))
|
||||
return MKDIR_SUCCESS;
|
||||
|
||||
if(errno == EEXIST)
|
||||
return MKDIR_EXISTS;
|
||||
|
||||
return MKDIR_ERROR;
|
||||
}
|
||||
|
Reference in New Issue
Block a user