platform.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (c) 2013 Hugh Bailey <[email protected]>
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #pragma once
  17. #include <stdio.h>
  18. #include <wchar.h>
  19. #include <sys/types.h>
  20. #include "c99defs.h"
  21. /*
  22. * Platform-independent functions for Accessing files, encoding, DLLs,
  23. * sleep, timer, and timing.
  24. */
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. EXPORT FILE *os_wfopen(const wchar_t *path, const char *mode);
  29. EXPORT FILE *os_fopen(const char *path, const char *mode);
  30. EXPORT off_t os_fgetsize(FILE *file);
  31. EXPORT size_t os_fread_mbs(FILE *file, char **pstr);
  32. EXPORT size_t os_fread_utf8(FILE *file, char **pstr);
  33. /* functions purely for convenience */
  34. EXPORT char *os_quick_read_utf8_file(const char *path);
  35. EXPORT bool os_quick_write_utf8_file(const char *path, const char *str,
  36. size_t len, bool marker);
  37. EXPORT char *os_quick_read_mbs_file(const char *path);
  38. EXPORT bool os_quick_write_mbs_file(const char *path, const char *str,
  39. size_t len);
  40. EXPORT size_t os_mbs_to_wcs(const char *str, size_t len, wchar_t **pstr);
  41. EXPORT size_t os_utf8_to_wcs(const char *str, size_t len, wchar_t **pstr);
  42. EXPORT size_t os_wcs_to_mbs(const wchar_t *str, size_t len, char **pstr);
  43. EXPORT size_t os_wcs_to_utf8(const wchar_t *str, size_t len, char **pstr);
  44. EXPORT size_t os_utf8_to_mbs(const char *str, size_t len, char **pstr);
  45. EXPORT size_t os_mbs_to_utf8(const char *str, size_t len, char **pstr);
  46. EXPORT void *os_dlopen(const char *path);
  47. EXPORT void *os_dlsym(void *module, const char *func);
  48. EXPORT void os_dlclose(void *module);
  49. EXPORT void os_sleepto_ns(uint64_t time_target);
  50. EXPORT void os_sleep_ms(uint32_t duration);
  51. EXPORT uint64_t os_gettime_ns(void);
  52. EXPORT char *os_get_config_path(const char *name);
  53. EXPORT bool os_file_exists(const char *path);
  54. #define MKDIR_EXISTS 1
  55. #define MKDIR_SUCCESS 0
  56. #define MKDIR_ERROR -1
  57. EXPORT int os_mkdir(const char *path);
  58. #ifdef _MSC_VER
  59. EXPORT int fseeko(FILE *stream, off_t offset, int whence);
  60. EXPORT off_t ftello(FILE *stream);
  61. #define strtoll _strtoi64
  62. #endif
  63. #ifdef __cplusplus
  64. }
  65. #endif