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