diff options
author | Thomas Martitz <kugel@rockbox.org> | 2010-05-03 15:12:19 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2010-05-03 15:12:19 +0000 |
commit | 69f8e8d277f3edd02d44ac1452d9471a5fedf2f1 (patch) | |
tree | 50d9ffbad95ae31e14a6fbfb5a272deff6dd9b29 /apps/misc.c | |
parent | b3f1eb8bbafdac59f2f532adaae97debbcf48a9b (diff) | |
download | rockbox-69f8e8d277f3edd02d44ac1452d9471a5fedf2f1.tar.gz rockbox-69f8e8d277f3edd02d44ac1452d9471a5fedf2f1.zip |
Move read_line() further down so that it can be used in checkwps and remove checkwps' copy if it.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25793 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/misc.c')
-rw-r--r-- | apps/misc.c | 74 |
1 files changed, 38 insertions, 36 deletions
diff --git a/apps/misc.c b/apps/misc.c index f9c6116205..eebcc9aebc 100644 --- a/apps/misc.c +++ b/apps/misc.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <stdlib.h> | 21 | #include <stdlib.h> |
22 | #include <ctype.h> | 22 | #include <ctype.h> |
23 | #include <string.h> | 23 | #include <string.h> |
24 | #include <errno.h> | ||
24 | #include "config.h" | 25 | #include "config.h" |
25 | #include "misc.h" | 26 | #include "misc.h" |
26 | #include "lcd.h" | 27 | #include "lcd.h" |
@@ -33,7 +34,6 @@ | |||
33 | #include "lang.h" | 34 | #include "lang.h" |
34 | #include "dir.h" | 35 | #include "dir.h" |
35 | #include "lcd-remote.h" | 36 | #include "lcd-remote.h" |
36 | #include "errno.h" | ||
37 | #include "system.h" | 37 | #include "system.h" |
38 | #include "timefuncs.h" | 38 | #include "timefuncs.h" |
39 | #include "screens.h" | 39 | #include "screens.h" |
@@ -158,41 +158,6 @@ bool warn_on_pl_erase(void) | |||
158 | return true; | 158 | return true; |
159 | } | 159 | } |
160 | 160 | ||
161 | /* Read (up to) a line of text from fd into buffer and return number of bytes | ||
162 | * read (which may be larger than the number of bytes stored in buffer). If | ||
163 | * an error occurs, -1 is returned (and buffer contains whatever could be | ||
164 | * read). A line is terminated by a LF char. Neither LF nor CR chars are | ||
165 | * stored in buffer. | ||
166 | */ | ||
167 | int read_line(int fd, char* buffer, int buffer_size) | ||
168 | { | ||
169 | int count = 0; | ||
170 | int num_read = 0; | ||
171 | |||
172 | errno = 0; | ||
173 | |||
174 | while (count < buffer_size) | ||
175 | { | ||
176 | unsigned char c; | ||
177 | |||
178 | if (1 != read(fd, &c, 1)) | ||
179 | break; | ||
180 | |||
181 | num_read++; | ||
182 | |||
183 | if ( c == '\n' ) | ||
184 | break; | ||
185 | |||
186 | if ( c == '\r' ) | ||
187 | continue; | ||
188 | |||
189 | buffer[count++] = c; | ||
190 | } | ||
191 | |||
192 | buffer[MIN(count, buffer_size - 1)] = 0; | ||
193 | |||
194 | return errno ? -1 : num_read; | ||
195 | } | ||
196 | 161 | ||
197 | /* Performance optimized version of the previous function. */ | 162 | /* Performance optimized version of the previous function. */ |
198 | int fast_readline(int fd, char *buf, int buf_size, void *parameters, | 163 | int fast_readline(int fd, char *buf, int buf_size, void *parameters, |
@@ -841,6 +806,43 @@ char *strip_extension(char* buffer, int buffer_size, const char *filename) | |||
841 | } | 806 | } |
842 | #endif /* !defined(__PCTOOL__) */ | 807 | #endif /* !defined(__PCTOOL__) */ |
843 | 808 | ||
809 | /* Read (up to) a line of text from fd into buffer and return number of bytes | ||
810 | * read (which may be larger than the number of bytes stored in buffer). If | ||
811 | * an error occurs, -1 is returned (and buffer contains whatever could be | ||
812 | * read). A line is terminated by a LF char. Neither LF nor CR chars are | ||
813 | * stored in buffer. | ||
814 | */ | ||
815 | int read_line(int fd, char* buffer, int buffer_size) | ||
816 | { | ||
817 | int count = 0; | ||
818 | int num_read = 0; | ||
819 | |||
820 | errno = 0; | ||
821 | |||
822 | while (count < buffer_size) | ||
823 | { | ||
824 | unsigned char c; | ||
825 | |||
826 | if (1 != read(fd, &c, 1)) | ||
827 | break; | ||
828 | |||
829 | num_read++; | ||
830 | |||
831 | if ( c == '\n' ) | ||
832 | break; | ||
833 | |||
834 | if ( c == '\r' ) | ||
835 | continue; | ||
836 | |||
837 | buffer[count++] = c; | ||
838 | } | ||
839 | |||
840 | buffer[MIN(count, buffer_size - 1)] = 0; | ||
841 | |||
842 | return errno ? -1 : num_read; | ||
843 | } | ||
844 | |||
845 | |||
844 | char* skip_whitespace(char* const str) | 846 | char* skip_whitespace(char* const str) |
845 | { | 847 | { |
846 | char *s = str; | 848 | char *s = str; |