view libcommon/exit.c @ 57:bccf028921bb

apdu-checksw command added to both fc-simtool and fc-uicc-tool
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 22 Mar 2021 23:58:11 +0000
parents 812779459ddd
children
line wrap: on
line source

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

extern unsigned calypso_fd;
extern FILE *cpipeF, *rpipeF;

calypso_poweroff()
{
	int c;

	fputs("poweroff\n", cpipeF);
	fflush(cpipeF);
	while ((c = getc(rpipeF)) != EOF)
		putchar(c);
	exit(0);
}

good_exit()
{
	if (calypso_fd)
		calypso_poweroff();
	exit(0);
}

cmd_exit(argc, argv)
	char **argv;
{
	if (argc < 2)
		good_exit();
	if (!calypso_fd) {
		fprintf(stderr,
	"error: exit arguments are only meaningful with Calypso back end\n");
		return(-1);
	}
	if (!strcmp(argv[1], "bare"))
		exit(0);
	if (!strcmp(argv[1], "iota-off"))
		calypso_poweroff();
	fprintf(stderr, "error: \"%s\" is not an understood exit mode\n",
		argv[1]);
	return(-1);
}