diff options
author | Rafaël Carré <funman@videolan.org> | 2012-05-07 01:30:45 -0400 |
---|---|---|
committer | Rafaël Carré <funman@videolan.org> | 2012-05-07 01:30:45 -0400 |
commit | dd57c01bef9bd24fc8000175f61bf6071901289a (patch) | |
tree | d95d188460cbb4401adf3b7f5309f51d862d6a1b /firmware/usbstack | |
parent | 803408f18657bcd501737ad29e98a1b4cca0ec37 (diff) |
simplify yearday_to_daymonth()
Diffstat (limited to 'firmware/usbstack')
-rw-r--r-- | firmware/usbstack/usb_storage.c | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/firmware/usbstack/usb_storage.c b/firmware/usbstack/usb_storage.c index 2da3e85a34..c1f278b0ff 100644 --- a/firmware/usbstack/usb_storage.c +++ b/firmware/usbstack/usb_storage.c @@ -333,25 +333,15 @@ static enum { #if CONFIG_RTC static void yearday_to_daymonth(int yd, int y, int *d, int *m) { - static const char tnl[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; - static const char tl[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; - const char *t; - int i=0; - - if((y%4 == 0 && y%100 != 0) || y%400 == 0) - { - t=tl; - } - else - { - t=tnl; - } + static char t[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + + bool leap = (y%4 == 0 && y%100 != 0) || y%400 == 0; + t[2] = leap ? 29 : 28; + + int i; + for (i = 0; i < 12 && yd >= t[i]; i++) + yd -= t[i]; - while(i<12 && yd >= t[i]) - { - yd-=t[i]; - i++; - } *d = yd+1; *m = i; } @@ -757,8 +747,7 @@ static void handle_scsi(struct command_block_wrapper* cbw) struct storage_info info; unsigned int length = cbw->data_transfer_length; - unsigned int block_size = 0; - unsigned int block_count = 0; + unsigned int block_size, block_count; bool lun_present=true; unsigned char lun = cbw->lun; unsigned int block_size_mult = 1; |