1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-12-17 04:08:34 +00:00
hashcat/src/logging.c

139 lines
1.8 KiB
C
Raw Normal View History

/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#if defined (__APPLE__)
2016-09-06 20:25:54 +00:00
#include <stdio.h>
#endif
#include "common.h"
#include "logging.h"
static int last_len = 0;
static int log_final (FILE *fp, const char *fmt, va_list ap)
{
if (last_len)
{
fputc ('\r', fp);
for (int i = 0; i < last_len; i++)
{
fputc (' ', fp);
}
fputc ('\r', fp);
}
char s[4096] = { 0 };
2016-09-30 16:39:31 +00:00
const size_t max_len = sizeof (s);
2016-09-30 16:39:31 +00:00
const int len = vsnprintf (s, max_len, fmt, ap);
2016-09-30 16:39:31 +00:00
//if (len > max_len) len = max_len;
2016-09-30 16:39:31 +00:00
fwrite (s, (size_t) len, 1, fp);
fflush (fp);
last_len = len;
2016-09-30 16:39:31 +00:00
return last_len;
}
int log_out_nn (FILE *fp, const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
const int len = log_final (fp, fmt, ap);
va_end (ap);
return len;
}
int log_info_nn (const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
const int len = log_final (stdout, fmt, ap);
va_end (ap);
return len;
}
int log_error_nn (const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
const int len = log_final (stderr, fmt, ap);
va_end (ap);
return len;
}
int log_out (FILE *fp, const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
const int len = log_final (fp, fmt, ap);
va_end (ap);
fputc ('\n', fp);
last_len = 0;
return len;
}
int log_info (const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
const int len = log_final (stdout, fmt, ap);
va_end (ap);
fputc ('\n', stdout);
last_len = 0;
return len;
}
int log_error (const char *fmt, ...)
{
fputc ('\n', stderr);
fputc ('\n', stderr);
va_list ap;
va_start (ap, fmt);
const int len = log_final (stderr, fmt, ap);
va_end (ap);
fputc ('\n', stderr);
fputc ('\n', stderr);
last_len = 0;
return len;
}