diff options
author | Pali Rohár <pali.rohar@gmail.com> | 2012-08-10 12:01:14 +0200 |
---|---|---|
committer | Pali Rohár <pali.rohar@gmail.com> | 2012-08-10 12:01:14 +0200 |
commit | ad68e324c61b708dfd903f2c5fda79f40b87b8bf (patch) | |
tree | e11e92e39ea5c9244be69f5f66d93339719873ed | |
parent | 34b55a222ef1ce3ecc18df12a96cd7eea5fffd60 (diff) | |
download | 0xFFFF-ad68e324c61b708dfd903f2c5fda79f40b87b8bf.tar.bz2 |
Fix ERROR macros
-rw-r--r-- | src/fiasco.c | 20 | ||||
-rw-r--r-- | src/global.h | 11 | ||||
-rw-r--r-- | src/image.c | 6 | ||||
-rw-r--r-- | src/main2.c | 28 | ||||
-rw-r--r-- | src/usb-device.c | 12 |
5 files changed, 40 insertions, 37 deletions
diff --git a/src/fiasco.c b/src/fiasco.c index 72d245b..6cc3e12 100644 --- a/src/fiasco.c +++ b/src/fiasco.c @@ -33,8 +33,8 @@ #include "image.h" #include "fiasco.h" -#define FIASCO_READ_ERROR(fiasco, format, ...) do { ERROR(errno, format, ##__VA_ARGS__); fiasco_free(fiasco); return NULL; } while (0) -#define FIASCO_WRITE_ERROR(file, fd, format, ...) do { ERROR(errno, "%s: " format, file, ##__VA_ARGS__); if ( fd >= 0 ) close(fd); return -1; } while (0) +#define FIASCO_READ_ERROR(fiasco, ...) do { ERROR_INFO(__VA_ARGS__); fiasco_free(fiasco); return NULL; } while (0) +#define FIASCO_WRITE_ERROR(file, fd, ...) do { ERROR_INFO_STR(file, __VA_ARGS__); if ( fd >= 0 ) close(fd); return -1; } while (0) #define READ_OR_FAIL(fiasco, buf, size) do { if ( read(fiasco->fd, buf, size) != size ) { FIASCO_READ_ERROR(fiasco, "Cannot read %d bytes", size); } } while (0) #define READ_OR_RETURN(fiasco, buf, size) do { if ( read(fiasco->fd, buf, size) != size ) return fiasco; } while (0) #define WRITE_OR_FAIL(file, fd, buf, size) do { if ( ! simulate ) { if ( write(fd, buf, size) != size ) { FIASCO_WRITE_ERROR(file, fd, "Cannot write %d bytes", size); } } } while (0) @@ -77,7 +77,7 @@ struct fiasco * fiasco_alloc_from_file(const char * file) { fiasco->fd = open(file, O_RDONLY); if ( fiasco->fd < 0 ) { - ERROR(errno, "Cannot open file"); + ERROR_INFO("Cannot open file"); fiasco_free(fiasco); return NULL; } @@ -122,7 +122,7 @@ struct fiasco * fiasco_alloc_from_file(const char * file) { /* Header of next image */ if ( ! buf[0] == 0x54 && buf[2] == 0x2E && buf[3] == 0x19 && buf[4] == 0x01 && buf[5] == 0x01 && buf[6] == 0x00 ) { - ERROR(0, "Invalid next image header"); + ERROR("Invalid next image header"); return fiasco; } @@ -290,7 +290,7 @@ int fiasco_write_to_file(struct fiasco * fiasco, const char * file) { if ( ! simulate ) { fd = open(file, O_RDWR|O_CREAT|O_TRUNC, 0644); if ( fd < 0 ) { - ERROR(errno, "Cannot create file"); + ERROR_INFO("Cannot create file"); return -1; } } @@ -490,12 +490,12 @@ int fiasco_unpack(struct fiasco * fiasco, const char * dir) { memset(cwd, 0, sizeof(cwd)); if ( ! getcwd(cwd, sizeof(cwd)) ) { - ERROR(errno, "Cannot store current directory"); + ERROR_INFO("Cannot store current directory"); return -1; } if ( chdir(dir) < 0 ) { - ERROR(errno, "Cannot change current directory to %s", dir); + ERROR_INFO("Cannot change current directory to %s", dir); return -1; } @@ -533,7 +533,7 @@ int fiasco_unpack(struct fiasco * fiasco, const char * dir) { fd = open(name, O_RDWR|O_CREAT|O_TRUNC, 0644); if ( fd < 0 ) { - ERROR(errno, "Cannot create output file %s", name); + ERROR_INFO("Cannot create output file %s", name); return -1; } @@ -553,7 +553,7 @@ int fiasco_unpack(struct fiasco * fiasco, const char * dir) { fd = open(layout_name, O_RDWR|O_CREAT|O_TRUNC, 0644); if ( fd < 0 ) { - ERROR(errno, "Cannot create layout file %s", layout_name); + ERROR_INFO("Cannot create layout file %s", layout_name); return -1; } @@ -571,7 +571,7 @@ int fiasco_unpack(struct fiasco * fiasco, const char * dir) { if ( dir ) { if ( chdir(cwd) < 0 ) { - ERROR(errno, "Cannot change current directory back to %s", cwd); + ERROR_INFO("Cannot change current directory back to %s", cwd); return -1; } } diff --git a/src/global.h b/src/global.h index ab7247a..6e4e866 100644 --- a/src/global.h +++ b/src/global.h @@ -10,11 +10,14 @@ extern int simulate; extern int noverify; extern int verbose; -#define VERBOSE(format, ...) do { if ( verbose ) { fprintf(stderr, format, ##__VA_ARGS__); } } while (0) -#define ERROR(errno, format, ...) do { fprintf(stderr, "Error: "); fprintf(stderr, format, ##__VA_ARGS__); if ( errno ) fprintf(stderr, ": %s\n", strerror(errno)); else fprintf(stderr, "\n"); } while (0) -#define WARNING(format, ...) do { fprintf(stderr, "Warning: "); fprintf(stderr, format, ##__VA_ARGS__); fprintf(stderr, "\n"); } while (0) +#define VERBOSE(...) do { if ( verbose ) { fprintf(stderr, __VA_ARGS__); } } while (0) +#define WARNING(...) do { fprintf(stderr, "Warning: "); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); } while (0) +#define ERROR_INFO_STR(str, ...) do { if ( str[0] ) fprintf(stderr, "Error: %s: ", str); else fprintf(stderr, "Error: "); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); } while (0) +#define ERROR_STR(str, ...) do { errno = 0; ERROR_INFO_STR(str, __VA_ARGS__); } while (0) +#define ERROR_INFO(...) do { ERROR_INFO_STR("", __VA_ARGS__); } while (0) +#define ERROR(...) do { ERROR_STR("", __VA_ARGS__); } while (0) -#define ALLOC_ERROR() do { ERROR(0, "Cannot allocate memory"); } while (0) +#define ALLOC_ERROR() do { ERROR("Cannot allocate memory"); } while (0) #define ALLOC_ERROR_RETURN(...) do { ALLOC_ERROR(); return __VA_ARGS__; } while (0) #endif diff --git a/src/image.c b/src/image.c index ba756c0..6e7d500 100644 --- a/src/image.c +++ b/src/image.c @@ -198,7 +198,7 @@ struct image * image_alloc_from_file(const char * file, const char * type, const image->is_shared_fd = 0; image->fd = open(file, O_RDONLY); if ( image->fd < 0 ) { - ERROR(errno, "Cannot open image file %s", file); + ERROR_INFO("Cannot open image file %s", file); free(image); return NULL; } @@ -234,7 +234,7 @@ struct image * image_alloc_from_shared_fd(int fd, size_t size, size_t offset, ui image_append(image, type, device, hwrevs, version, layout); if ( ! noverify && image->hash != hash ) { - ERROR(0, "Image hash mishmash (counted %#04x, got %#04x)", image->hash, hash); + ERROR("Image hash mishmash (counted %#04x, got %#04x)", image->hash, hash); image_free(image); return NULL; } @@ -314,7 +314,7 @@ size_t image_read(struct image * image, void * buf, size_t count) { else new_count = count - ret_count; - memset(buf+ret_count, 0xFF, new_count); + memset((unsigned char *)buf+ret_count, 0xFF, new_count); ret_count += new_count; image->acur += new_count; diff --git a/src/main2.c b/src/main2.c index b68e825..c360e96 100644 --- a/src/main2.c +++ b/src/main2.c @@ -204,12 +204,12 @@ static void parse_image_arg(char * arg, struct image_list ** image_first) { off_t len; int fd = open(layout_file, O_RDONLY); if ( fd < 0 ) { - ERROR(errno, "Cannot open layout file %s", layout_file); + ERROR_INFO("Cannot open layout file %s", layout_file); exit(1); } len = lseek(fd, 0, SEEK_END); if ( len == (off_t)-1 ) { - ERROR(errno, "Cannot get size of file %s", layout_file); + ERROR_INFO("Cannot get size of file %s", layout_file); exit(1); } lseek(fd, 0, SEEK_SET); @@ -219,7 +219,7 @@ static void parse_image_arg(char * arg, struct image_list ** image_first) { exit(1); } if ( read(fd, layout, len) != len ) { - ERROR(errno, "Cannot read %lu bytes from layout file %s", len, layout_file); + ERROR_INFO("Cannot read %lu bytes from layout file %s", len, layout_file); exit(1); } } @@ -230,7 +230,7 @@ static void parse_image_arg(char * arg, struct image_list ** image_first) { free(layout); if ( ! image ) { - ERROR(0, "Cannot load image file %s", file); + ERROR("Cannot load image file %s", file); exit(1); } @@ -491,7 +491,7 @@ int main(int argc, char **argv) { /* load images from files */ if ( image_first && image_fiasco ) { - ERROR(0, "Cannot specify normal and fiasco images together"); + ERROR("Cannot specify normal and fiasco images together"); ret = 1; goto clean; } @@ -500,7 +500,7 @@ int main(int argc, char **argv) { if ( image_fiasco ) { fiasco_in = fiasco_alloc_from_file(image_fiasco_arg); if ( ! fiasco_in ) - ERROR(0, "Cannot load fiasco image file %s", image_fiasco_arg); + ERROR("Cannot load fiasco image file %s", image_fiasco_arg); else image_first = fiasco_in->first; } @@ -509,7 +509,7 @@ int main(int argc, char **argv) { if ( filter_type ) { enum image_type type = image_type_from_string(filter_type_arg); if ( ! type ) { - ERROR(0, "Specified unknown image type for filtering: %s", filter_type_arg); + ERROR("Specified unknown image type for filtering: %s", filter_type_arg); } else { image_ptr = image_first; while ( image_ptr ) { @@ -528,7 +528,7 @@ int main(int argc, char **argv) { if ( filter_device ) { enum device device = device_from_string(filter_device_arg); if ( ! device ) { - ERROR(0, "Specified unknown device for filtering: %s", filter_device_arg); + ERROR("Specified unknown device for filtering: %s", filter_device_arg); } else { image_ptr = image_first; while ( image_ptr ) { @@ -631,7 +631,7 @@ int main(int argc, char **argv) { fiasco_print_info(fiasco_in); printf("\n"); } else if ( ! image_first ) { - ERROR(0, "No image specified"); + ERROR("No image specified"); ret = 1; goto clean; } @@ -672,7 +672,7 @@ int main(int argc, char **argv) { *(swver++) = 0; fiasco_out = fiasco_alloc_empty(); if ( ! fiasco_out ) { - ERROR(0, "Cannot write images to fiasco file %s", fiasco_gen_arg); + ERROR("Cannot write images to fiasco file %s", fiasco_gen_arg); } else { if ( swver ) strcpy(fiasco_out->swver, swver); @@ -690,21 +690,21 @@ int main(int argc, char **argv) { if ( dev_cold_flash ) { if ( have_2nd == 0 ) { - ERROR(0, "2nd image for Cold Flashing was not specified"); + ERROR("2nd image for Cold Flashing was not specified"); ret = 1; goto clean; } else if ( have_2nd == 2 ) { - ERROR(0, "More 2nd images for Cold Flashing was specified"); + ERROR("More 2nd images for Cold Flashing was specified"); ret = 1; goto clean; } if ( have_secondary == 0 ) { - ERROR(0, "Secondary image for Cold Flashing was not specified"); + ERROR("Secondary image for Cold Flashing was not specified"); ret = 1; goto clean; } else if ( have_secondary == 2 ) { - ERROR(0, "More Secondary images for Cold Flashing was specified"); + ERROR("More Secondary images for Cold Flashing was specified"); ret = 1; goto clean; } diff --git a/src/usb-device.c b/src/usb-device.c index 69e4997..400924d 100644 --- a/src/usb-device.c +++ b/src/usb-device.c @@ -34,7 +34,7 @@ static int prev = 0; #define PRINTF_ADD(format, ...) do { prev += printf(format, ##__VA_ARGS__); } while (0) #define PRINTF_LINE(format, ...) do { PRINTF_BACK(); PRINTF_ADD(format, ##__VA_ARGS__); fflush(stdout); } while (0) #define PRINTF_END() do { if ( prev ) { printf("\n"); prev = 0; } } while (0) -#define PRINTF_ERROR(errno, format, ...) do { PRINTF_END(); ERROR(errno, format, ##__VA_ARGS__); } while (0) +#define PRINTF_ERROR(format, ...) do { PRINTF_END(); ERROR_INFO(format, ##__VA_ARGS__); } while (0) static struct usb_flash_device usb_devices[] = { { 0x0421, 0x0105, 2, 1, -1, FLASH_NOLO, { DEVICE_SU_18, DEVICE_RX_44, DEVICE_RX_48, DEVICE_RX_51, 0 } }, @@ -43,7 +43,7 @@ static struct usb_flash_device usb_devices[] = { { 0x0421, 0x01c8, -1, -1, -1, FLASH_MKII, { DEVICE_RX_51, 0 } }, { 0x0421, 0x0431, 0, -1, -1, FLASH_DISK, { DEVICE_SU_18, DEVICE_RX_34, 0 } }, { 0x0421, 0x3f00, 2, 1, -1, FLASH_NOLO, { DEVICE_RX_34, 0 } }, - { 0, 0, -1, -1, -1, 0, {} } + { 0, } }; static const char * usb_flash_protocols[] = { @@ -92,7 +92,7 @@ static struct usb_device_info * usb_device_is_valid(struct usb_device * dev) { PRINTF_LINE("Opening USB..."); usb_dev_handle * udev = usb_open(dev); if ( ! udev ) { - PRINTF_ERROR(errno, "usb_open failed"); + PRINTF_ERROR("usb_open failed"); return NULL; } @@ -103,7 +103,7 @@ static struct usb_device_info * usb_device_is_valid(struct usb_device * dev) { PRINTF_LINE("Claiming USB interface..."); if ( usb_claim_interface(udev, usb_devices[i].interface) < 0 ) { - PRINTF_ERROR(errno, "usb_claim_interface failed"); + PRINTF_ERROR("usb_claim_interface failed"); usb_close(udev); return NULL; } @@ -111,7 +111,7 @@ static struct usb_device_info * usb_device_is_valid(struct usb_device * dev) { if ( usb_devices[i].alternate >= 0 ) { PRINTF_LINE("Setting alternate USB interface..."); if ( usb_set_altinterface(udev, usb_devices[i].alternate) < 0 ) { - PRINTF_ERROR(errno, "usb_claim_interface failed"); + PRINTF_ERROR("usb_claim_interface failed"); usb_close(udev); return NULL; } @@ -120,7 +120,7 @@ static struct usb_device_info * usb_device_is_valid(struct usb_device * dev) { if ( usb_devices[i].configuration >= 0 ) { PRINTF_LINE("Setting USB configuration..."); if ( usb_set_configuration(udev, usb_devices[i].configuration) < 0 ) { - PRINTF_ERROR(errno, "usb_set_configuration failed"); + PRINTF_ERROR("usb_set_configuration failed"); usb_close(udev); return NULL; } |