static int log_print_header(LogContext *pContext) { int result; if ((result=log_file_lock(pContext->log_fd)) != 0) { return result; } pContext->current_size = lseek(pContext->log_fd, 0, SEEK_END); if (pContext->current_size < 0) { result = errno != 0 ? errno : EACCES; log_file_unlock(pContext->log_fd); fprintf(stderr, "lseek file \"%s\" fail, " \ "errno: %d, error info: %s\n", \ pContext->log_filename, result, STRERROR(result)); return result; } if (pContext->current_size == 0) { pContext->print_header_callback(pContext); } log_file_unlock(pContext->log_fd); return 0; }
void my_lock_trace(FILE *stream, const char *func, const unsigned int line, char *fmt, ...) { log_file_lock(); fprintf(g_stream, "%s(%d):", func, line); va_list ap; va_start(ap, fmt); vfprintf(g_stream, fmt, ap); va_end(ap); fprintf(g_stream, "\n"); fflush(g_stream); log_file_unlock(); }