From c4481f8d920fc9b42ad501221e9567ad59398228 Mon Sep 17 00:00:00 2001 From: Noe Rubinstein Date: Wed, 17 Oct 2012 17:28:13 +0200 Subject: Print errors to stderr --- build_rom.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/build_rom.c b/build_rom.c index 70a1583..6ed43b5 100644 --- a/build_rom.c +++ b/build_rom.c @@ -55,8 +55,8 @@ mac mac_between(mac from, mac to); unsigned get_next_serial(void); void set_next_serial(unsigned serial); void choose_macs(mac from, mac to, struct xioh_data *xioh_data); -void print_mac_le(mac mac); -void print_mac_be(mac mac); +void print_mac_le(FILE* h, mac mac); +void print_mac_be(FILE* h, mac mac); void reverse(uint8_t *t, int n); void write_serial(struct serial *serial); void dump_xioh_data(struct xioh_data *xioh_data); @@ -207,7 +207,7 @@ void write_standalone(const char *fname, struct xioh_data *xioh_data) { FILE *f = fopen(fname, "w"); if (!f) { - printf("Can't open file \"%s\": %s\n", fname, strerror(errno)); + fprintf(stderr, "Can't open file \"%s\": %s\n", fname, strerror(errno)); exit(errno); } @@ -219,12 +219,12 @@ void write_xioh_data(const char *fname, struct xioh_data *xioh_data) { FILE *rom = fopen(fname, "r+"); if (!rom) { - printf("Can't open file \"%s\": %s\n", fname, strerror(errno)); + fprintf(stderr, "Can't open file \"%s\": %s\n", fname, strerror(errno)); exit(errno); } if(fseek(rom, XIOH_DATA_OFFSET, SEEK_SET)) { - printf("Can't seek: %s\n", strerror(errno)); + fprintf(stderr, "Can't seek: %s\n", strerror(errno)); exit(errno); } @@ -256,7 +256,7 @@ void dump_xioh_data(struct xioh_data *xioh_data) printf("MAC addresses:\n"); for (i = 0; i < MAC_NUM; i++) { printf("\t"); - print_mac_be(xioh_data->addr[i]); + print_mac_be(stdout, xioh_data->addr[i]); printf("\n"); } } @@ -287,7 +287,7 @@ void set_next_serial(unsigned serial) { FILE *f = fopen(next_serial, "w"); if (!f) { - printf("Can't open file \"%s\": %s\n", next_serial, strerror(errno)); + fprintf(stderr, "Can't open file \"%s\": %s\n", next_serial, strerror(errno)); exit(errno); } fprintf(f, "%u", serial); @@ -371,15 +371,15 @@ bool mac_used(const char *fname, mac *addr) unsigned i; if (!f) { - printf("Can't open file \"%s\": %s\n", fname, strerror(errno)); + fprintf(stderr, "Can't open file \"%s\": %s\n", fname, strerror(errno)); exit(errno); } while (0 < fread(&xioh_data, sizeof(xioh_data), 1, f)) { for (i = 0; i < MAC_NUM; i++) if (xioh_data.addr[i].n == addr->n) { - print_mac_le(*addr); - printf(" already used\n"); + print_mac_le(stderr, *addr); + fprintf(stderr, " already used\n"); fclose(f); return true; } @@ -404,13 +404,13 @@ bool serial_used(const char *fname, int serial) struct xioh_data xioh_data; if (!f) { - printf("Can't open file \"%s\": %s\n", fname, strerror(errno)); + fprintf(stderr, "Can't open file \"%s\": %s\n", fname, strerror(errno)); exit(errno); } while (0 < fread(&xioh_data, sizeof(xioh_data), 1, f)) { if (xioh_data.serial.number == serial) { - printf("Serial number %d already used! Trying %d.\n", serial, serial+1); + fprintf(stderr, "Serial number %d already used! Trying %d.\n", serial, serial+1); fclose(f); return true; } @@ -428,7 +428,7 @@ void record_use(char *fname, struct xioh_data *xioh_data) #ifdef OLD_DB_FORMAT FILE *f = fopen(fname, "a"); if (!f) { - printf("Can't open file \"%s\": %s\n", fname, strerror(errno)); + fprintf(stderr, "Can't open file \"%s\": %s\n", fname, strerror(errno)); exit(errno); } @@ -498,16 +498,16 @@ bool parse_mac(char* src, union mac *dst) dst->b+5, dst->b+4, dst->b+3, dst->b+2, dst->b+1, dst->b+0); } -void print_mac_le(union mac mac) +void print_mac_le(FILE* h, union mac mac) { - printf("%02x:%02x:%02x:%02x:%02x:%02x", + fprintf(h, "%02x:%02x:%02x:%02x:%02x:%02x", mac.b[5], mac.b[4], mac.b[3], mac.b[2], mac.b[1], mac.b[0]); } -void print_mac_be(union mac mac) +void print_mac_be(FILE* h, union mac mac) { - printf("%02x:%02x:%02x:%02x:%02x:%02x", + fprintf(h, "%02x:%02x:%02x:%02x:%02x:%02x", mac.b[0], mac.b[1], mac.b[2], mac.b[3], mac.b[4], mac.b[5]); } -- cgit v1.2.3