Some improvements to error handling.
This commit is contained in:
parent
a324600117
commit
9937ad3cba
22
crc64.c
22
crc64.c
@ -100,13 +100,13 @@ int _dowildcard = -1;
|
|||||||
/* Signal handler */
|
/* Signal handler */
|
||||||
/* ======================================================================== */
|
/* ======================================================================== */
|
||||||
|
|
||||||
static volatile int g_stop_flag = 0;
|
static int g_interrupted_flag = 0;
|
||||||
|
|
||||||
static void sigint_handler(const int sig)
|
static void sigint_handler(const int sig)
|
||||||
{
|
{
|
||||||
if (sig == SIGINT)
|
if (sig == SIGINT)
|
||||||
{
|
{
|
||||||
g_stop_flag = 1;
|
g_interrupted_flag = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,7 +256,7 @@ static int process(const CHAR *const file_name, const int options)
|
|||||||
goto clean_up;
|
goto clean_up;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((!feof(input)) && (!g_stop_flag))
|
while (!feof(input))
|
||||||
{
|
{
|
||||||
const size_t count = fread(buffer, sizeof(uint8_t), BUFF_SIZE, input);
|
const size_t count = fread(buffer, sizeof(uint8_t), BUFF_SIZE, input);
|
||||||
if (count > 0U)
|
if (count > 0U)
|
||||||
@ -279,6 +279,10 @@ static int process(const CHAR *const file_name, const int options)
|
|||||||
break; /*ignore the read error*/
|
break; /*ignore the read error*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (g_interrupted_flag)
|
||||||
|
{
|
||||||
|
goto clean_up; /*process was interrupted*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options & OPT_NEGATE)
|
if (options & OPT_NEGATE)
|
||||||
@ -415,7 +419,7 @@ int MAIN(int argc, CHAR *argv[])
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FPRINTF(stderr, T("Option \"--%s\" is not recognized!\n"), arg_val);
|
FPRINTF(stderr, T("Error: Option \"--%s\" is not recognized!\n"), arg_val);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -456,7 +460,7 @@ int MAIN(int argc, CHAR *argv[])
|
|||||||
|
|
||||||
if (arg_off < argc)
|
if (arg_off < argc)
|
||||||
{
|
{
|
||||||
while ((arg_off < argc) && (!g_stop_flag))
|
while ((arg_off < argc) && (!g_interrupted_flag))
|
||||||
{
|
{
|
||||||
if (process(argv[arg_off++], options) != EXIT_SUCCESS)
|
if (process(argv[arg_off++], options) != EXIT_SUCCESS)
|
||||||
{
|
{
|
||||||
@ -479,13 +483,13 @@ int MAIN(int argc, CHAR *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_stop_flag && (!(options & OPT_SILENT)))
|
if (g_interrupted_flag && (!(options & OPT_IGNERR)))
|
||||||
|
{
|
||||||
|
if (!(options & OPT_SILENT))
|
||||||
{
|
{
|
||||||
FPUTS(T("Error: Process was interrupted!\n"), stderr);
|
FPUTS(T("Error: Process was interrupted!\n"), stderr);
|
||||||
if (!(options & OPT_IGNERR))
|
|
||||||
{
|
|
||||||
exit_code = 128 + SIGINT;
|
|
||||||
}
|
}
|
||||||
|
exit_code = 128 + SIGINT;
|
||||||
}
|
}
|
||||||
|
|
||||||
return exit_code;
|
return exit_code;
|
||||||
|
Loading…
Reference in New Issue
Block a user