Exemplo n.º 1
0
Arquivo: xor.c Projeto: rprinz08/UP42
int xor(const char *inputFileName, const char *outputFileName, char *key) {
	FILE *inputFile, *outputFile;
	int keyLen;
	char *parsedKey = NULL;

	setbuf(stdout, NULL);

	if(!strcmp(inputFileName, "-"))
		inputFile = stdin;
	else
		inputFile = fopen(inputFileName, "rb");

	if(!inputFile) {
		printError(stderr, "opening input file (%s)", inputFileName);
		return(EXIT_INPUT_FILE_ERROR);
	}

	if(!strcmp(outputFileName, "-"))
		outputFile = stdout;
	else
		outputFile = fopen(outputFileName, "wb");

	if(!outputFile) {
		printError(stderr, "opening output file (%s)", outputFileName);
		return(EXIT_OUTPUT_FILE_ERROR);
	}

	try {
		parseKey(key, &keyLen);
		xorFile(inputFile, outputFile, parsedKey, keyLen);
	}
	catch(RuntimeException) {
		const e4c_exception *exception = e4c_get_exception();
		e4c_print_exception(exception);
		return(EXIT_UNKNOWN_ERROR);
	}
	finally {
		if(inputFile != stdin)
			fclose(inputFile);

		if(outputFile != stdout)
			fclose(outputFile);
	}

	return(EXIT_OK);
}
Exemplo n.º 2
0
int main(int argc, char *argv[]) {
	int r = 0;
	e4c_using_context(E4C_FALSE) {
		e4c_context_set_handlers(NULL, NULL, BackTrace_create_for_exception, BackTrace_destroy);
		try {
			myfunc();
		}
		catch (RuntimeException) {
			const e4c_exception *e = e4c_get_exception();
			fprintf(stderr, "%s: %s", e->name, e->message);
			if (e->custom_data) {
				BackTrace_dump(e->custom_data);
			}
			r = 1;
		}
	}
	return r;
}
Exemplo n.º 3
0
int library_3rd_party(int foobar){

    volatile int status = LIBRARY_SUCCESS;

    /* We know that the client is exception-unaware */
    TEST_ASSERT( !e4c_context_is_ready() );

    {
        e4c_reusing_context(status, LIBRARY_FAILURE){

            E4C_TRY{

                library_function(foobar);

            }E4C_CATCH(RuntimeException){

                TEST_ASSERT( e4c_is_instance_of(e4c_get_exception(), &IllegalArgumentException) );
            }
        }
    }