Revision 5f3adef4 dclog/log.c

View differences:

dclog/log.c
38 38
        DCLogSetHeader( dclog, 1 );
39 39
        DCLogSetPrintLevel( dclog, 1 );
40 40

  
41
#if !WIN32 && !MAC_OS
42 41
	logstream = open_memstream(&logbuffer, &logbuffer_size);
43 42
	if (!logstream) {
44 43
		fprintf(stderr, "Unable to initialize logger, exiting");
45 44
		exit(-1);
46 45
	}
47
#else
48
        logbuffer_size=1000;
49
	logbuffer = (char *) malloc(logbuffer_size);
50
#endif
51 46
        initialized = 1;
52 47
}
53 48

  
......
65 60

  
66 61
	if (!initialized) return;
67 62

  
63
	rewind(logstream);
68 64

  
69 65
  	va_start( str_args, fmt );
70
#if !WIN32 && !MAC_OS
71
	rewind(logstream);
72 66
  	if (vfprintf( logstream, fmt, str_args ) < 0) return;
67
  	va_end( str_args );
68

  
73 69
	char zero = 0;
74 70
	if (fwrite(&zero, 1, 1, logstream) != 1) return;
75 71
	fflush(logstream);
76
#else
77
        if (vsnprintf( logbuffer, logbuffer_size, fmt, str_args) < 0) return;
78
        logbuffer[logbuffer_size - 1] = '\0';
79
#endif
80
  	va_end( str_args );
81 72

  
82
//fprintf(stderr, "X.do logger lev:%d, msg %s\n", lev, logbuffer);
83 73
	DCLogWrite(dclog, lev , logbuffer);
84
        fflush(dclog->fp);
85 74
}
86 75

  

Also available in: Unified diff