Browse Subversion Repository
Contents of /branches/mty-makai/log.c
Parent Directory
| Revision Log
Revision 260 -
( show annotations)
( download)
( as text)
Wed Jan 12 09:00:49 2011 UTC
(13 years, 3 months ago)
by notanpe
File MIME type: text/x-csrc
File size: 2351 byte(s)
特殊検索を実装。
gettid() をちょっとマシにした。
| 1 |
/*********************************************************************** |
| 2 |
* |
| 3 |
* file: log.c |
| 4 |
* |
| 5 |
* $Id: log.c 244 2010-03-16 13:54:51Z chapuni $ |
| 6 |
* |
| 7 |
*/ |
| 8 |
|
| 9 |
#include <errno.h> |
| 10 |
#include <stdarg.h> |
| 11 |
#include <stdio.h> |
| 12 |
#include <stdlib.h> |
| 13 |
#include <time.h> |
| 14 |
#include <sys/timeb.h> |
| 15 |
|
| 16 |
#if defined(WIN32) |
| 17 |
|
| 18 |
#include <windows.h> |
| 19 |
#include <process.h> |
| 20 |
|
| 21 |
#elif defined(__GNUC__) |
| 22 |
|
| 23 |
#include <sys/time.h> |
| 24 |
|
| 25 |
#endif |
| 26 |
|
| 27 |
#include "log.h" |
| 28 |
|
| 29 |
static HANDLE mutex_log; |
| 30 |
static FILE *ofp; |
| 31 |
|
| 32 |
int |
| 33 |
log_open(char const *name) |
| 34 |
{ |
| 35 |
if ((ofp = fopen(name, "at")) == NULL) |
| 36 |
{ |
| 37 |
perror("log.txt"); |
| 38 |
return errno; |
| 39 |
} |
| 40 |
|
| 41 |
setvbuf(ofp, NULL, _IONBF, BUFSIZ); /* XXX MSVCRT ĹÍ _IOLBF ŞúŇĘčÉŽěľČ˘ */ |
| 42 |
|
| 43 |
mutex_log = CreateMutex(NULL, FALSE, NULL); |
| 44 |
|
| 45 |
return 0; |
| 46 |
} |
| 47 |
|
| 48 |
static |
| 49 |
int |
| 50 |
log_printf(FILE *fp, char const *fmt, ...) |
| 51 |
{ |
| 52 |
int r; |
| 53 |
va_list ap; |
| 54 |
va_start(ap, fmt); |
| 55 |
vfprintf(stdout, fmt, ap); |
| 56 |
if ( fp == NULL ) { |
| 57 |
fp = ofp; |
| 58 |
} |
| 59 |
r = vfprintf(fp, fmt, ap); |
| 60 |
va_end(ap); |
| 61 |
if (r > 0) |
| 62 |
return r; |
| 63 |
perror("log_printf"); |
| 64 |
exit(errno); |
| 65 |
} |
| 66 |
|
| 67 |
void |
| 68 |
log_print(FILE *fp, int full, char const *hash, uint8_t const *key) |
| 69 |
{ |
| 70 |
struct timeb tb; |
| 71 |
struct tm *plt; |
| 72 |
extern char fixedSalt[2]; |
| 73 |
|
| 74 |
/* qbg; ü˘ĆżĺÁĆᤠ*/ |
| 75 |
ftime(&tb); |
| 76 |
plt = localtime(&tb.time); |
| 77 |
|
| 78 |
WaitForSingleObject(mutex_log, INFINITE); |
| 79 |
|
| 80 |
if (full && fixedSalt[0] == '\0') |
| 81 |
{ |
| 82 |
log_printf(fp, "%s #%s" |
| 83 |
"\t%04d/%02d/%02d %02d:%02d:%02d.%03d" |
| 84 |
"\t(%02X %02X %02X %02X %02X %02X %02X %02X/%02X)\n", |
| 85 |
hash, |
| 86 |
key, |
| 87 |
plt->tm_year + 1900, |
| 88 |
plt->tm_mon + 1, |
| 89 |
plt->tm_mday, |
| 90 |
plt->tm_hour, |
| 91 |
plt->tm_min, |
| 92 |
plt->tm_sec, |
| 93 |
tb.millitm, |
| 94 |
key[0], key[1], key[2], key[3], |
| 95 |
key[4], key[5], key[6], key[7], |
| 96 |
key[8]); |
| 97 |
} |
| 98 |
else |
| 99 |
{ |
| 100 |
log_printf(fp, "%s ##%02x%02x%02x%02x%02x%02x%02x%02x%s" |
| 101 |
"\t%04d/%02d/%02d %02d:%02d:%02d.%03d" |
| 102 |
"\t \n", /* ccBÜA˘ÁŠ */ |
| 103 |
hash, |
| 104 |
key[0], key[1], key[2], key[3], |
| 105 |
key[4], key[5], key[6], key[7], |
| 106 |
fixedSalt, |
| 107 |
plt->tm_year + 1900, |
| 108 |
plt->tm_mon + 1, |
| 109 |
plt->tm_mday, |
| 110 |
plt->tm_hour, |
| 111 |
plt->tm_min, |
| 112 |
plt->tm_sec, |
| 113 |
tb.millitm); |
| 114 |
} |
| 115 |
ReleaseMutex(mutex_log); |
| 116 |
} |
| 117 |
|
| 118 |
/* |
| 119 |
* Local Variables: |
| 120 |
* tab-width: 4 |
| 121 |
* End: |
| 122 |
* |
| 123 |
* EOF */ |
| |