-
Notifications
You must be signed in to change notification settings - Fork 6
/
log.c
112 lines (91 loc) · 2.97 KB
/
log.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* $Id: log.c,v 1.6 2005/05/15 20:15:28 harbourn Exp $
* dcfldd - The Enhanced Forensic DD
* By Nicholas Harbour
*/
/* Copyright (C) 85, 90, 91, 1995-2001, 2005 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* GNU dd originally written by Paul Rubin, David MacKenzie, and Stuart Kemp. */
#include "dcfldd.h"
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <string.h>
#include "log.h"
#include "hash.h"
#include "verify.h"
#include <stdarg.h>
#include "hashformat.h"
FILE *errlog = NULL;
void syscall_error(char *str)
{
syscall_error_noexit(str);
exit(1);
}
void syscall_error_noexit(char *str)
{
char *errstr = strerror(errno);
fprintf(stderr, "%s:%s: %s\n", program_name, str == NULL ? "" : str, errstr);
if (errlog != NULL)
fprintf(errlog, "%s:%s: %s\n", program_name, str == NULL ? "" : str, errstr);
}
void user_error(char *str, ...)
{
va_list ap;
va_start(ap, str);
fprintf(stderr, "%s: ", program_name);
vfprintf(stderr, str, ap);
fprintf(stderr, "\n");
if (errlog != NULL) {
fprintf(errlog, "%s: ", program_name);
vfprintf(errlog, str, ap);
fprintf(errlog, "\n");
}
va_end(ap);
exit(1);
}
void log_info(char *str, ...)
{
va_list ap;
va_start(ap, str);
vfprintf(stderr, str, ap);
if (errlog != NULL) {
vfprintf(errlog, str, ap);
}
va_end(ap);
}
void internal_error(char *str)
{
fprintf(stderr, "%s: internal error: %s\n", program_name, str);
if (errlog != NULL)
fprintf(errlog, "%s: internal error: %s\n", program_name, str);
exit(1);
}
void log_hashwindow(hashtype_t *htype, off_t wina, off_t winb, size_t bs, char *hash)
{
print_fmt(hashformat, htype->log, wina, winb, bs, htype->name, hash);
}
void log_hashtotal(hashtype_t *htype, off_t wina, off_t winb, size_t bs, char *hash)
{
print_fmt(totalhashformat, htype->log, wina, winb, bs, htype->name, hash);
}
void log_verifywindow(hashtype_t *htype, off_t wina, off_t winb, int mismatch)
{
fprintf(htype->log, "%llu - %llu: %s\n",
(unsigned long long int) wina,
(unsigned long long int) winb,
mismatch ? "Mismatch" : "Match");
}
void log_verifytotal(hashtype_t *htype, int mismatch)
{
fprintf(htype->log, "Total: %s\n", mismatch ? "Mismatch" : "Match");
}