diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/settings.c | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/apps/settings.c b/apps/settings.c index c17f42fd52..417f0f324f 100644 --- a/apps/settings.c +++ b/apps/settings.c | |||
@@ -41,6 +41,8 @@ | |||
41 | #include "screens.h" | 41 | #include "screens.h" |
42 | #include "ctype.h" | 42 | #include "ctype.h" |
43 | #include "file.h" | 43 | #include "file.h" |
44 | #include "errno.h" | ||
45 | #include "system.h" | ||
44 | #ifdef HAVE_LCD_BITMAP | 46 | #ifdef HAVE_LCD_BITMAP |
45 | #include "icons.h" | 47 | #include "icons.h" |
46 | #include "font.h" | 48 | #include "font.h" |
@@ -581,9 +583,18 @@ void settings_load(void) | |||
581 | settings_apply(); | 583 | settings_apply(); |
582 | } | 584 | } |
583 | 585 | ||
586 | /* Read (up to) a line of text from fd into buffer and return number of bytes | ||
587 | * read (which may be larger than the number of bytes stored in buffer). If | ||
588 | * an error occurs, -1 is returned (and buffer contains whatever could be | ||
589 | * read). A line is terminated by a LF char. Neither LF nor CR chars are | ||
590 | * stored in buffer. | ||
591 | */ | ||
584 | static int read_line(int fd, char* buffer, int buffer_size) | 592 | static int read_line(int fd, char* buffer, int buffer_size) |
585 | { | 593 | { |
586 | int count = 0; | 594 | int count = 0; |
595 | int num_read = 0; | ||
596 | |||
597 | errno = 0; | ||
587 | 598 | ||
588 | while (count < buffer_size) | 599 | while (count < buffer_size) |
589 | { | 600 | { |
@@ -592,6 +603,8 @@ static int read_line(int fd, char* buffer, int buffer_size) | |||
592 | if (1 != read(fd, &c, 1)) | 603 | if (1 != read(fd, &c, 1)) |
593 | break; | 604 | break; |
594 | 605 | ||
606 | num_read++; | ||
607 | |||
595 | if ( c == '\n' ) | 608 | if ( c == '\n' ) |
596 | break; | 609 | break; |
597 | 610 | ||
@@ -601,12 +614,9 @@ static int read_line(int fd, char* buffer, int buffer_size) | |||
601 | buffer[count++] = c; | 614 | buffer[count++] = c; |
602 | } | 615 | } |
603 | 616 | ||
604 | if ( count < buffer_size ) | 617 | buffer[MIN(count, buffer_size - 1)] = 0; |
605 | buffer[count] = 0; | ||
606 | else | ||
607 | buffer[buffer_size-1] = 0; | ||
608 | 618 | ||
609 | return count; | 619 | return errno ? -1 : num_read; |
610 | } | 620 | } |
611 | 621 | ||
612 | /* parse a line from a configuration file. the line format is: | 622 | /* parse a line from a configuration file. the line format is: |
@@ -656,6 +666,12 @@ static void set_sound(char* value, int type, int* setting) | |||
656 | 666 | ||
657 | *setting = num; | 667 | *setting = num; |
658 | mpeg_sound_set(type, num); | 668 | mpeg_sound_set(type, num); |
669 | |||
670 | #ifdef HAVE_MAS3507D | ||
671 | /* This is required to actually apply balance */ | ||
672 | if (SOUND_BALANCE == type) | ||
673 | mpeg_sound_set(SOUND_VOLUME, global_settings.volume); | ||
674 | #endif | ||
659 | } | 675 | } |
660 | 676 | ||
661 | bool settings_load_config(char* file) | 677 | bool settings_load_config(char* file) |
@@ -667,7 +683,7 @@ bool settings_load_config(char* file) | |||
667 | if (-1 == fd) | 683 | if (-1 == fd) |
668 | return false; | 684 | return false; |
669 | 685 | ||
670 | while (read_line(fd, line, sizeof line)) | 686 | while (read_line(fd, line, sizeof line) > 0) |
671 | { | 687 | { |
672 | char* name; | 688 | char* name; |
673 | char* value; | 689 | char* value; |
@@ -786,12 +802,12 @@ bool set_bool(char* string, bool* variable ) | |||
786 | bool set_bool_options(char* string, bool* variable, | 802 | bool set_bool_options(char* string, bool* variable, |
787 | char* yes_str, char* no_str ) | 803 | char* yes_str, char* no_str ) |
788 | { | 804 | { |
789 | char* names[] = { yes_str, no_str }; | 805 | char* names[] = { no_str, yes_str }; |
790 | int value = !*variable; | 806 | int value = *variable; |
791 | bool result; | 807 | bool result; |
792 | 808 | ||
793 | result = set_option(string, &value, names, 2, NULL); | 809 | result = set_option(string, &value, names, 2, NULL); |
794 | *variable = !value; | 810 | *variable = value; |
795 | return result; | 811 | return result; |
796 | } | 812 | } |
797 | 813 | ||