HologramDepthmap Library
sys.cpp
Go to the documentation of this file.
1 #include "graphics/sys.h"
2 #include <stdarg.h>
3 #include <stdio.h>
4 
5 static FILE *fp;
6 
7 void file_log(const char *fmt, ...)
8 {
9 #ifdef __CSKETCH_DEBUG
10  if (fp == 0) {
11  fp = fopen("my_log.txt", "w+t");
12  }
13  va_list ap;
14 
15  va_start(ap, fmt);
16  vfprintf(fp, fmt, ap);
17  va_end(ap);
18  fflush(fp);
19 #endif
20 
21 }
22 
23 #ifdef _MAC_OS
24 void * memalign(size_t align, size_t sz)
25 {
26  /* this a hack so that runlog can link with mallocs that don't have */
27  /* memalign */
28  void *p = malloc(sz + align + 1);
29  size_t d = (unsigned long)p % align;
30 
31  if (d != 0)
32  p = (char *)p + align - d;
33 
34  return p;
35 }
36 #endif
37 
38 FILE* file_read_open(const WChar* fname)
39 {
40 #ifdef _WIN32
41  return _wfopen(fname, L"r+b");
42 #else
43  return fopen(fname, "r+b");
44 #endif
45 }
46 
47 FILE* file_write_open(const WChar* fname)
48 {
49 #ifdef _WIN32
50  return _wfopen(fname, L"w+b");
51 #else
52  return fopen(fname, "w+b");
53 #endif
54 }
55 
56 FILE* file_read_open(const WChar* fname, const WChar* mode)
57 {
58 #ifdef _WIN32
59  return _wfopen(fname, mode);
60 #else
61  return fopen(fname, mode);
62 #endif
63 }
64 
65 FILE* file_write_open(const WChar* fname, const WChar* mode)
66 {
67 #ifdef _WIN32
68  return _wfopen(fname, mode);
69 #else
70  return fopen(fname, mode);
71 #endif
72 }
73 
74 WChar* string_cpy(WChar* dest, const WChar* src)
75 {
76 #ifdef _WIN32
77  return wcscpy(dest, src);
78 #else
79  return strcpy(dest, src);
80 #endif
81 }
82 
83 WChar* string_cat(WChar* dest, const WChar* src)
84 {
85 #ifdef _WIN32
86  return wcscat(dest, src);
87 #else
88  return strcat(dest, src);
89 #endif
90 }
91 
92 int string_cmp(const WChar* str1, const WChar* str2)
93 {
94 #ifdef _WIN32
95  return wcscmp(str1, str2);
96 #else
97  return strcmp(str1, str2);
98 #endif
99 }
100 
void file_log(const char *fmt,...)
Definition: sys.cpp:7
static FILE * fp
Definition: sys.cpp:5
FILE * file_write_open(const WChar *fname)
Definition: sys.cpp:47
FILE * file_read_open(const WChar *fname)
Definition: sys.cpp:38
int string_cmp(const WChar *str1, const WChar *str2)
Definition: sys.cpp:92
WChar * string_cat(WChar *dest, const WChar *src)
Definition: sys.cpp:83
WChar * string_cpy(WChar *dest, const WChar *src)
Definition: sys.cpp:74