NXEngine v1.0.0.2
[NXEngine.git] / common / stat.cpp
blobbb1f460edf065bc44e2b6e460b9f9d8a42cf653b
2 #include <stdio.h>
3 #include <stdarg.h>
4 #include <string.h>
5 #include <time.h>
7 #include "basics.h"
8 #include "misc.fdh"
10 #define MAXBUFSIZE 1024
11 char logfilename[64] = { 0 };
12 void writelog(const char *buf, bool append_cr);
15 void SetLogFilename(const char *fname)
17 maxcpy(logfilename, fname, sizeof(logfilename));
18 remove(logfilename);
20 stat("Log set %d", time(NULL));
23 void writelog(const char *buf, bool append_cr)
25 FILE *fp;
27 fp = fopen(logfilename, "a+");
28 if (fp)
30 fputs(buf, fp);
31 if (append_cr) fputc('\n', fp);
33 fclose(fp);
38 void c------------------------------() {}
41 void stat(const char *fmt, ...)
43 va_list ar;
44 char buffer[MAXBUFSIZE];
46 va_start(ar, fmt);
47 vsnprintf(buffer, sizeof(buffer), fmt, ar);
48 va_end(ar);
50 puts(buffer);
51 fflush(stdout);
53 if (logfilename[0])
54 writelog(buffer, true);
57 void staterr(const char *fmt, ...)
59 va_list ar;
60 char buffer[MAXBUFSIZE];
62 va_start(ar, fmt);
63 vsnprintf(buffer, sizeof(buffer), fmt, ar);
64 va_end(ar);
66 printf(" error << %s >> \n", buffer);
67 fflush(stdout);
69 if (logfilename[0])
71 writelog(" error << ", false);
72 writelog(buffer, false);
73 writelog(" >>\n", false);
78 char *stprintf(const char *fmt, ...)
80 va_list ar;
81 char *str = GetStaticStr();
83 va_start(ar, fmt);
84 vsnprintf(str, 255, fmt, ar);
85 va_end(ar);
87 return str;