2010-12-15 23:45:21 +01:00
|
|
|
/*
|
2011-02-20 13:02:15 +01:00
|
|
|
Copyright (C) 2006-2011 Con Kolivas
|
2011-02-21 06:11:59 +01:00
|
|
|
Copyright (C) 2008, 2011 Peter Hyman
|
2010-12-15 23:45:21 +01:00
|
|
|
Copyright (C) 1998 Andrew Tridgell
|
2010-11-04 11:14:55 +01:00
|
|
|
|
2010-03-29 01:07:08 +02:00
|
|
|
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 of the License, or
|
|
|
|
|
(at your option) any later version.
|
2010-12-15 23:45:21 +01:00
|
|
|
|
2010-03-29 01:07:08 +02:00
|
|
|
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.
|
2010-12-15 23:45:21 +01:00
|
|
|
|
2010-03-29 01:07:08 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
2010-12-15 23:45:21 +01:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-03-29 01:07:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Utilities used in rzip
|
|
|
|
|
|
|
|
|
|
tridge, June 1996
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Realloc removed
|
|
|
|
|
* Functions added
|
|
|
|
|
* read_config()
|
|
|
|
|
* Peter Hyman, December 2008
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "rzip.h"
|
|
|
|
|
|
2011-03-08 22:32:14 +01:00
|
|
|
static const char *infile = NULL;
|
|
|
|
|
static char delete_infile = 0;
|
|
|
|
|
static const char *outfile = NULL;
|
|
|
|
|
static char delete_outfile = 0;
|
|
|
|
|
static FILE *outputfile = NULL;
|
|
|
|
|
|
|
|
|
|
void register_infile(const char *name, char delete)
|
|
|
|
|
{
|
|
|
|
|
infile = name;
|
|
|
|
|
delete_infile = delete;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void register_outfile(const char *name, char delete)
|
|
|
|
|
{
|
|
|
|
|
outfile = name;
|
|
|
|
|
delete_outfile = delete;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void register_outputfile(FILE *f)
|
|
|
|
|
{
|
|
|
|
|
outputfile = f;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-21 04:17:05 +01:00
|
|
|
static void unlink_files(void)
|
|
|
|
|
{
|
|
|
|
|
/* Delete temporary files generated for testing or faking stdio */
|
2011-03-08 22:32:14 +01:00
|
|
|
if (outfile && delete_outfile)
|
|
|
|
|
unlink(outfile);
|
2011-02-21 04:17:05 +01:00
|
|
|
|
2011-03-08 22:32:14 +01:00
|
|
|
if (infile && delete_infile)
|
|
|
|
|
unlink(infile);
|
2011-02-21 04:17:05 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-21 06:11:59 +01:00
|
|
|
static void fatal_exit(void)
|
|
|
|
|
{
|
|
|
|
|
unlink_files();
|
2011-03-08 22:32:14 +01:00
|
|
|
fprintf(outputfile, "Fatal error - exiting\n");
|
|
|
|
|
fflush(outputfile);
|
2011-02-21 06:11:59 +01:00
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-21 04:51:20 +01:00
|
|
|
/* Failure when there is likely to be a meaningful error in perror */
|
2010-03-29 01:07:08 +02:00
|
|
|
void fatal(const char *format, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
|
|
if (format) {
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
vfprintf(stderr, format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-04 11:14:55 +01:00
|
|
|
perror(NULL);
|
2011-02-21 06:11:59 +01:00
|
|
|
fatal_exit();
|
2010-03-29 01:07:08 +02:00
|
|
|
}
|
|
|
|
|
|
2011-02-21 04:51:20 +01:00
|
|
|
void failure(const char *format, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
|
|
if (format) {
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
vfprintf(stderr, format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-21 06:11:59 +01:00
|
|
|
fatal_exit();
|
2011-02-21 04:51:20 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-29 01:07:08 +02:00
|
|
|
void sighandler()
|
|
|
|
|
{
|
2011-02-21 04:17:05 +01:00
|
|
|
unlink_files();
|
2010-03-29 01:07:08 +02:00
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-21 14:49:50 +01:00
|
|
|
void round_to_page(i64 *size)
|
|
|
|
|
{
|
2011-03-08 22:32:14 +01:00
|
|
|
*size -= *size % PAGE_SIZE;
|
2011-02-21 14:49:50 +01:00
|
|
|
if (unlikely(!*size))
|
2011-03-08 22:32:14 +01:00
|
|
|
*size = PAGE_SIZE;
|
2011-02-21 14:49:50 +01:00
|
|
|
}
|