2013-12-25 21:40:33 -08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013 Hugh 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
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2013-10-14 04:21:15 -07:00
|
|
|
#pragma once
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <wchar.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include "c99defs.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Platform-independent functions for Accessing files, encoding, DLLs,
|
|
|
|
* sleep, timer, and timing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
EXPORT FILE *os_wfopen(const wchar_t *path, const char *mode);
|
|
|
|
EXPORT FILE *os_fopen(const char *path, const char *mode);
|
2014-05-16 00:18:23 -07:00
|
|
|
EXPORT int64_t os_fgetsize(FILE *file);
|
|
|
|
|
2016-04-03 18:02:45 -07:00
|
|
|
#ifdef _WIN32
|
|
|
|
EXPORT int os_stat(const char *file, struct stat *st);
|
|
|
|
#else
|
|
|
|
#define os_stat stat
|
|
|
|
#endif
|
|
|
|
|
2014-05-16 00:18:23 -07:00
|
|
|
EXPORT int os_fseeki64(FILE *file, int64_t offset, int origin);
|
|
|
|
EXPORT int64_t os_ftelli64(FILE *file);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
EXPORT size_t os_fread_mbs(FILE *file, char **pstr);
|
|
|
|
EXPORT size_t os_fread_utf8(FILE *file, char **pstr);
|
|
|
|
|
|
|
|
/* functions purely for convenience */
|
|
|
|
EXPORT char *os_quick_read_utf8_file(const char *path);
|
|
|
|
EXPORT bool os_quick_write_utf8_file(const char *path, const char *str,
|
|
|
|
size_t len, bool marker);
|
2015-08-21 17:31:23 -07:00
|
|
|
EXPORT bool os_quick_write_utf8_file_safe(const char *path, const char *str,
|
|
|
|
size_t len, bool marker, const char *temp_ext,
|
|
|
|
const char *backup_ext);
|
2013-10-17 17:21:42 -07:00
|
|
|
EXPORT char *os_quick_read_mbs_file(const char *path);
|
|
|
|
EXPORT bool os_quick_write_mbs_file(const char *path, const char *str,
|
|
|
|
size_t len);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2015-02-20 14:50:51 -08:00
|
|
|
EXPORT int64_t os_get_file_size(const char *path);
|
2015-02-20 14:52:13 -08:00
|
|
|
EXPORT int64_t os_get_free_space(const char *path);
|
2015-02-20 14:50:51 -08:00
|
|
|
|
2014-05-22 03:42:43 -07:00
|
|
|
EXPORT size_t os_mbs_to_wcs(const char *str, size_t str_len, wchar_t *dst,
|
|
|
|
size_t dst_size);
|
|
|
|
EXPORT size_t os_utf8_to_wcs(const char *str, size_t len, wchar_t *dst,
|
|
|
|
size_t dst_size);
|
|
|
|
EXPORT size_t os_wcs_to_mbs(const wchar_t *str, size_t len, char *dst,
|
|
|
|
size_t dst_size);
|
|
|
|
EXPORT size_t os_wcs_to_utf8(const wchar_t *str, size_t len, char *dst,
|
|
|
|
size_t dst_size);
|
2014-03-04 06:07:13 -08:00
|
|
|
|
|
|
|
EXPORT size_t os_mbs_to_wcs_ptr(const char *str, size_t len, wchar_t **pstr);
|
|
|
|
EXPORT size_t os_utf8_to_wcs_ptr(const char *str, size_t len, wchar_t **pstr);
|
|
|
|
EXPORT size_t os_wcs_to_mbs_ptr(const wchar_t *str, size_t len, char **pstr);
|
|
|
|
EXPORT size_t os_wcs_to_utf8_ptr(const wchar_t *str, size_t len, char **pstr);
|
|
|
|
|
|
|
|
EXPORT size_t os_utf8_to_mbs_ptr(const char *str, size_t len, char **pstr);
|
|
|
|
EXPORT size_t os_mbs_to_utf8_ptr(const char *str, size_t len, char **pstr);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2015-03-21 13:23:41 -07:00
|
|
|
EXPORT double os_strtod(const char *str);
|
|
|
|
EXPORT int os_dtostr(double value, char *dst, size_t size);
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
EXPORT void *os_dlopen(const char *path);
|
|
|
|
EXPORT void *os_dlsym(void *module, const char *func);
|
|
|
|
EXPORT void os_dlclose(void *module);
|
|
|
|
|
2014-07-04 22:20:20 -07:00
|
|
|
struct os_cpu_usage_info;
|
2014-09-25 17:44:05 -07:00
|
|
|
typedef struct os_cpu_usage_info os_cpu_usage_info_t;
|
2014-07-04 22:20:20 -07:00
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
EXPORT os_cpu_usage_info_t *os_cpu_usage_info_start(void);
|
|
|
|
EXPORT double os_cpu_usage_info_query(os_cpu_usage_info_t *info);
|
|
|
|
EXPORT void os_cpu_usage_info_destroy(os_cpu_usage_info_t *info);
|
2014-07-04 22:20:20 -07:00
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
typedef const void os_performance_token_t;
|
|
|
|
EXPORT os_performance_token_t *os_request_high_performance(const char *reason);
|
|
|
|
EXPORT void os_end_high_performance(os_performance_token_t *);
|
2014-08-21 20:21:27 -07:00
|
|
|
|
2014-02-09 04:51:06 -08:00
|
|
|
/**
|
|
|
|
* Sleeps to a specific time (in nanoseconds). Doesn't have to be super
|
|
|
|
* accurate in terms of actual slept time because the target time is ensured.
|
|
|
|
* Returns false if already at or past target time.
|
|
|
|
*/
|
|
|
|
EXPORT bool os_sleepto_ns(uint64_t time_target);
|
2013-09-30 19:37:13 -07:00
|
|
|
EXPORT void os_sleep_ms(uint32_t duration);
|
|
|
|
|
|
|
|
EXPORT uint64_t os_gettime_ns(void);
|
|
|
|
|
2015-01-15 23:44:38 -08:00
|
|
|
EXPORT int os_get_config_path(char *dst, size_t size, const char *name);
|
|
|
|
EXPORT char *os_get_config_path_ptr(const char *name);
|
2013-11-01 14:33:00 -07:00
|
|
|
|
2016-07-06 01:29:05 -07:00
|
|
|
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);
|
|
|
|
|
2013-12-12 20:41:46 -08:00
|
|
|
EXPORT bool os_file_exists(const char *path);
|
|
|
|
|
2015-10-14 20:16:44 -07:00
|
|
|
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);
|
|
|
|
|
2016-06-15 16:18:56 -07:00
|
|
|
EXPORT const char *os_get_path_extension(const char *path);
|
|
|
|
|
2014-05-14 17:44:32 -07:00
|
|
|
struct os_dir;
|
2014-09-25 17:44:05 -07:00
|
|
|
typedef struct os_dir os_dir_t;
|
2014-05-14 17:44:32 -07:00
|
|
|
|
|
|
|
struct os_dirent {
|
|
|
|
char d_name[256];
|
|
|
|
bool directory;
|
|
|
|
};
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
EXPORT os_dir_t *os_opendir(const char *path);
|
|
|
|
EXPORT struct os_dirent *os_readdir(os_dir_t *dir);
|
|
|
|
EXPORT void os_closedir(os_dir_t *dir);
|
2014-05-14 17:44:32 -07:00
|
|
|
|
2014-07-27 01:29:39 -07:00
|
|
|
struct os_globent {
|
|
|
|
char *path;
|
|
|
|
bool directory;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct os_glob_info {
|
|
|
|
size_t gl_pathc;
|
|
|
|
struct os_globent *gl_pathv;
|
|
|
|
};
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
typedef struct os_glob_info os_glob_t;
|
2014-07-27 01:29:39 -07:00
|
|
|
|
|
|
|
/* currently no flags available */
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
EXPORT int os_glob(const char *pattern, int flags, os_glob_t **pglob);
|
|
|
|
EXPORT void os_globfree(os_glob_t *pglob);
|
2014-07-27 01:29:39 -07:00
|
|
|
|
2014-05-14 17:44:32 -07:00
|
|
|
EXPORT int os_unlink(const char *path);
|
2015-06-29 00:39:21 -07:00
|
|
|
EXPORT int os_rmdir(const char *path);
|
2014-05-14 17:44:32 -07:00
|
|
|
|
2015-07-16 00:50:21 -07:00
|
|
|
EXPORT char *os_getcwd(char *path, size_t size);
|
|
|
|
EXPORT int os_chdir(const char *path);
|
|
|
|
|
2013-11-23 22:35:03 -08:00
|
|
|
#define MKDIR_EXISTS 1
|
|
|
|
#define MKDIR_SUCCESS 0
|
|
|
|
#define MKDIR_ERROR -1
|
|
|
|
|
|
|
|
EXPORT int os_mkdir(const char *path);
|
2015-07-08 10:00:33 -07:00
|
|
|
EXPORT int os_mkdirs(const char *path);
|
2015-06-21 22:33:48 -07:00
|
|
|
EXPORT int os_rename(const char *old_path, const char *new_path);
|
2015-06-29 00:39:56 -07:00
|
|
|
EXPORT int os_copyfile(const char *file_in, const char *file_out);
|
2013-11-23 22:35:03 -08:00
|
|
|
|
2016-12-05 04:32:37 -08:00
|
|
|
EXPORT char *os_generate_formatted_filename(const char *extension, bool space,
|
|
|
|
const char *format);
|
|
|
|
|
2015-09-12 19:18:03 -07:00
|
|
|
struct os_inhibit_info;
|
|
|
|
typedef struct os_inhibit_info os_inhibit_t;
|
|
|
|
|
|
|
|
EXPORT os_inhibit_t *os_inhibit_sleep_create(const char *reason);
|
|
|
|
EXPORT bool os_inhibit_sleep_set_active(os_inhibit_t *info, bool active);
|
|
|
|
EXPORT void os_inhibit_sleep_destroy(os_inhibit_t *info);
|
|
|
|
|
2015-11-18 12:09:13 -08:00
|
|
|
EXPORT void os_breakpoint(void);
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define strtoll _strtoi64
|
2015-05-04 09:27:29 -07:00
|
|
|
#if _MSC_VER < 1900
|
|
|
|
#define snprintf _snprintf
|
|
|
|
#endif
|
2013-11-07 15:45:03 -08:00
|
|
|
#endif
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2015-07-14 18:04:15 -07:00
|
|
|
#ifdef __APPLE__
|
|
|
|
# define ARCH_BITS 64
|
|
|
|
#else
|
|
|
|
# ifdef _WIN32
|
|
|
|
# ifdef _WIN64
|
|
|
|
# define ARCH_BITS 64
|
|
|
|
# else
|
|
|
|
# define ARCH_BITS 32
|
|
|
|
# endif
|
|
|
|
# else
|
|
|
|
# ifdef __LP64__
|
|
|
|
# define ARCH_BITS 64
|
|
|
|
# else
|
|
|
|
# define ARCH_BITS 32
|
|
|
|
# endif
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|