New upstream version 0.15.4+dfsg1
This commit is contained in:
parent
55d5047af0
commit
67704ac59c
359 changed files with 8423 additions and 1050 deletions
|
|
@ -264,6 +264,15 @@ static inline int cf_next_name(struct cf_parser *p, char **dst,
|
|||
return cf_get_name(p, dst, name, goto_token);
|
||||
}
|
||||
|
||||
static inline int cf_next_token_copy(struct cf_parser *p, char **dst)
|
||||
{
|
||||
if (!cf_next_valid_token(p))
|
||||
return PARSE_EOF;
|
||||
|
||||
cf_copy_token(p, dst);
|
||||
return PARSE_SUCCESS;
|
||||
}
|
||||
|
||||
static inline int cf_get_name_ref(struct cf_parser *p, struct strref *dst,
|
||||
const char *name, const char *goto_token)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -237,9 +237,11 @@ static inline void dstr_copy_dstr(struct dstr *dst, const struct dstr *src)
|
|||
if (dst->array)
|
||||
dstr_free(dst);
|
||||
|
||||
dstr_ensure_capacity(dst, src->len + 1);
|
||||
memcpy(dst->array, src->array, src->len + 1);
|
||||
dst->len = src->len;
|
||||
if (src->len) {
|
||||
dstr_ensure_capacity(dst, src->len + 1);
|
||||
memcpy(dst->array, src->array, src->len + 1);
|
||||
dst->len = src->len;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void dstr_reserve(struct dstr *dst, const size_t capacity)
|
||||
|
|
|
|||
|
|
@ -69,11 +69,12 @@ uint64_t os_gettime_ns(void)
|
|||
return f();
|
||||
}
|
||||
|
||||
/* gets the location ~/Library/Application Support/[name] */
|
||||
int os_get_config_path(char *dst, size_t size, const char *name)
|
||||
/* gets the location [domain mask]/Library/Application Support/[name] */
|
||||
static int os_get_path_internal(char *dst, size_t size, const char *name,
|
||||
NSSearchPathDomainMask domainMask)
|
||||
{
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(
|
||||
NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
||||
NSApplicationSupportDirectory, domainMask, YES);
|
||||
|
||||
if([paths count] == 0)
|
||||
bcrash("Could not get home directory (platform-cocoa)");
|
||||
|
|
@ -87,10 +88,11 @@ int os_get_config_path(char *dst, size_t size, const char *name)
|
|||
return snprintf(dst, size, "%s/%s", base_path, name);
|
||||
}
|
||||
|
||||
char *os_get_config_path_ptr(const char *name)
|
||||
static char *os_get_path_ptr_internal(const char *name,
|
||||
NSSearchPathDomainMask domainMask)
|
||||
{
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(
|
||||
NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
||||
NSApplicationSupportDirectory, domainMask, YES);
|
||||
|
||||
if([paths count] == 0)
|
||||
bcrash("Could not get home directory (platform-cocoa)");
|
||||
|
|
@ -113,6 +115,26 @@ char *os_get_config_path_ptr(const char *name)
|
|||
return path.array;
|
||||
}
|
||||
|
||||
int os_get_config_path(char *dst, size_t size, const char *name)
|
||||
{
|
||||
return os_get_path_internal(dst, size, name, NSUserDomainMask);
|
||||
}
|
||||
|
||||
char *os_get_config_path_ptr(const char *name)
|
||||
{
|
||||
return os_get_path_ptr_internal(name, NSUserDomainMask);
|
||||
}
|
||||
|
||||
int os_get_program_data_path(char *dst, size_t size, const char *name)
|
||||
{
|
||||
return os_get_path_internal(dst, size, name, NSLocalDomainMask);
|
||||
}
|
||||
|
||||
char *os_get_program_data_path_ptr(const char *name)
|
||||
{
|
||||
return os_get_path_ptr_internal(name, NSLocalDomainMask);
|
||||
}
|
||||
|
||||
struct os_cpu_usage_info {
|
||||
int64_t last_cpu_time;
|
||||
int64_t last_sys_time;
|
||||
|
|
|
|||
|
|
@ -49,7 +49,11 @@ void *os_dlopen(const char *path)
|
|||
return NULL;
|
||||
|
||||
dstr_init_copy(&dylib_name, path);
|
||||
#ifdef __APPLE__
|
||||
if (!dstr_find(&dylib_name, ".so") && !dstr_find(&dylib_name, ".dylib"))
|
||||
#else
|
||||
if (!dstr_find(&dylib_name, ".so"))
|
||||
#endif
|
||||
dstr_cat(&dylib_name, ".so");
|
||||
|
||||
void *res = dlopen(dylib_name.array, RTLD_LAZY);
|
||||
|
|
@ -68,7 +72,8 @@ void *os_dlsym(void *module, const char *func)
|
|||
|
||||
void os_dlclose(void *module)
|
||||
{
|
||||
dlclose(module);
|
||||
if (module)
|
||||
dlclose(module);
|
||||
}
|
||||
|
||||
#if !defined(__APPLE__)
|
||||
|
|
@ -236,6 +241,20 @@ char *os_get_config_path_ptr(const char *name)
|
|||
#endif
|
||||
}
|
||||
|
||||
int os_get_program_data_path(char *dst, size_t size, const char *name)
|
||||
{
|
||||
return snprintf(dst, size, "/usr/local/share/%s", !!name ? name : "");
|
||||
}
|
||||
|
||||
char *os_get_program_data_path_ptr(const char *name)
|
||||
{
|
||||
size_t len = snprintf(NULL, 0, "/usr/local/share/%s", !!name ? name : "");
|
||||
char *str = bmalloc(len + 1);
|
||||
snprintf(str, len + 1, "/usr/local/share/%s", !!name ? name : "");
|
||||
str[len] = 0;
|
||||
return str;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
bool os_file_exists(const char *path)
|
||||
|
|
|
|||
|
|
@ -208,12 +208,13 @@ uint64_t os_gettime_ns(void)
|
|||
return (uint64_t)time_val;
|
||||
}
|
||||
|
||||
/* returns %appdata%\[name] on windows */
|
||||
int os_get_config_path(char *dst, size_t size, const char *name)
|
||||
/* returns [folder]\[name] on windows */
|
||||
static int os_get_path_internal(char *dst, size_t size, const char *name,
|
||||
int folder)
|
||||
{
|
||||
wchar_t path_utf16[MAX_PATH];
|
||||
|
||||
SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT,
|
||||
SHGetFolderPathW(NULL, folder, NULL, SHGFP_TYPE_CURRENT,
|
||||
path_utf16);
|
||||
|
||||
if (os_wcs_to_utf8(path_utf16, 0, dst, size) != 0) {
|
||||
|
|
@ -231,13 +232,13 @@ int os_get_config_path(char *dst, size_t size, const char *name)
|
|||
return -1;
|
||||
}
|
||||
|
||||
char *os_get_config_path_ptr(const char *name)
|
||||
static char *os_get_path_ptr_internal(const char *name, int folder)
|
||||
{
|
||||
char *ptr;
|
||||
wchar_t path_utf16[MAX_PATH];
|
||||
struct dstr path;
|
||||
|
||||
SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT,
|
||||
SHGetFolderPathW(NULL, folder, NULL, SHGFP_TYPE_CURRENT,
|
||||
path_utf16);
|
||||
|
||||
os_wcs_to_utf8_ptr(path_utf16, 0, &ptr);
|
||||
|
|
@ -247,6 +248,26 @@ char *os_get_config_path_ptr(const char *name)
|
|||
return path.array;
|
||||
}
|
||||
|
||||
int os_get_config_path(char *dst, size_t size, const char *name)
|
||||
{
|
||||
return os_get_path_internal(dst, size, name, CSIDL_APPDATA);
|
||||
}
|
||||
|
||||
char *os_get_config_path_ptr(const char *name)
|
||||
{
|
||||
return os_get_path_ptr_internal(name, CSIDL_APPDATA);
|
||||
}
|
||||
|
||||
int os_get_program_data_path(char *dst, size_t size, const char *name)
|
||||
{
|
||||
return os_get_path_internal(dst, size, name, CSIDL_COMMON_APPDATA);
|
||||
}
|
||||
|
||||
char *os_get_program_data_path_ptr(const char *name)
|
||||
{
|
||||
return os_get_path_ptr_internal(name, CSIDL_COMMON_APPDATA);
|
||||
}
|
||||
|
||||
bool os_file_exists(const char *path)
|
||||
{
|
||||
WIN32_FIND_DATAW wfd;
|
||||
|
|
|
|||
|
|
@ -633,3 +633,26 @@ int os_mkdirs(const char *dir)
|
|||
dstr_free(&dir_str);
|
||||
return ret;
|
||||
}
|
||||
|
||||
const char *os_get_path_extension(const char *path)
|
||||
{
|
||||
struct dstr temp;
|
||||
size_t pos = 0;
|
||||
char *period;
|
||||
char *slash;
|
||||
|
||||
dstr_init_copy(&temp, path);
|
||||
dstr_replace(&temp, "\\", "/");
|
||||
|
||||
slash = strrchr(temp.array, '/');
|
||||
period = strrchr(temp.array, '.');
|
||||
if (period)
|
||||
pos = (size_t)(period - temp.array);
|
||||
|
||||
dstr_free(&temp);
|
||||
|
||||
if (!period || slash > period)
|
||||
return NULL;
|
||||
|
||||
return path + pos;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,11 +108,16 @@ EXPORT uint64_t os_gettime_ns(void);
|
|||
EXPORT int os_get_config_path(char *dst, size_t size, const char *name);
|
||||
EXPORT char *os_get_config_path_ptr(const char *name);
|
||||
|
||||
EXPORT int os_get_program_data_path(char *dst, size_t size, const char *name);
|
||||
EXPORT char *os_get_program_data_path_ptr(const char *name);
|
||||
|
||||
EXPORT bool os_file_exists(const char *path);
|
||||
|
||||
EXPORT size_t os_get_abs_path(const char *path, char *abspath, size_t size);
|
||||
EXPORT char *os_get_abs_path_ptr(const char *path);
|
||||
|
||||
EXPORT const char *os_get_path_extension(const char *path);
|
||||
|
||||
struct os_dir;
|
||||
typedef struct os_dir os_dir_t;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue