END_TEST /*----------------------------------------------------------------------- * Built-in errors */ START_TEST(test_error_prefix) { DESCRIBE_TEST; cork_error_clear(); cork_error_set_printf (CORK_UNKNOWN_ERROR, "%u errors occurred", (unsigned int) 17); fail_unless_streq("Error messages", "17 errors occurred", cork_error_message()); cork_error_prefix("The %s is aborting because ", "program"); fail_unless_streq("Error messages", "The program is aborting because 17 errors occurred", cork_error_message()); cork_error_clear(); }
END_TEST START_TEST(test_system_error) { DESCRIBE_TEST; /* Artificially flag a system error and make sure we can detect it */ errno = ENOMEM; cork_error_clear(); cork_system_error_set(); fail_unless(cork_error_code() == ENOMEM, "Expected a system error"); printf("Got error: %s\n", cork_error_message()); cork_error_clear(); }
static int cork_read_pipe_read(struct cork_read_pipe *p, char *buf, bool *progress) { if (p->fds[0] == -1) { return 0; } do { DEBUG("[read] Reading from pipe %d\n", p->fds[0]); ssize_t bytes_read = read(p->fds[0], buf, BUF_SIZE); if (bytes_read == -1) { if (errno == EAGAIN) { /* We've exhausted all of the data currently available. */ DEBUG("[read] No more bytes without blocking\n"); return 0; } else if (errno == EINTR) { /* Interrupted by a signal; return so that our wait loop can * catch that. */ DEBUG("[read] Interrupted by signal\n"); return 0; } else { /* An actual error */ cork_system_error_set(); DEBUG("[read] Error: %s\n", cork_error_message()); return -1; } } else if (bytes_read == 0) { DEBUG("[read] End of stream\n"); *progress = true; rii_check(cork_stream_consumer_eof(p->consumer)); rii_check_posix(close(p->fds[0])); p->fds[0] = -1; return 0; } else { DEBUG("[read] Got %zd bytes\n", bytes_read); *progress = true; rii_check(cork_stream_consumer_data (p->consumer, buf, bytes_read, p->first)); p->first = false; } } while (true); }