forked from len0rd/rockbox
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
This commit is contained in:
parent
b3f1eb8bba
commit
69f8e8d277
2 changed files with 38 additions and 66 deletions
74
apps/misc.c
74
apps/misc.c
|
@ -21,6 +21,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "lcd.h"
|
#include "lcd.h"
|
||||||
|
@ -33,7 +34,6 @@
|
||||||
#include "lang.h"
|
#include "lang.h"
|
||||||
#include "dir.h"
|
#include "dir.h"
|
||||||
#include "lcd-remote.h"
|
#include "lcd-remote.h"
|
||||||
#include "errno.h"
|
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "timefuncs.h"
|
#include "timefuncs.h"
|
||||||
#include "screens.h"
|
#include "screens.h"
|
||||||
|
@ -158,41 +158,6 @@ bool warn_on_pl_erase(void)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read (up to) a line of text from fd into buffer and return number of bytes
|
|
||||||
* read (which may be larger than the number of bytes stored in buffer). If
|
|
||||||
* an error occurs, -1 is returned (and buffer contains whatever could be
|
|
||||||
* read). A line is terminated by a LF char. Neither LF nor CR chars are
|
|
||||||
* stored in buffer.
|
|
||||||
*/
|
|
||||||
int read_line(int fd, char* buffer, int buffer_size)
|
|
||||||
{
|
|
||||||
int count = 0;
|
|
||||||
int num_read = 0;
|
|
||||||
|
|
||||||
errno = 0;
|
|
||||||
|
|
||||||
while (count < buffer_size)
|
|
||||||
{
|
|
||||||
unsigned char c;
|
|
||||||
|
|
||||||
if (1 != read(fd, &c, 1))
|
|
||||||
break;
|
|
||||||
|
|
||||||
num_read++;
|
|
||||||
|
|
||||||
if ( c == '\n' )
|
|
||||||
break;
|
|
||||||
|
|
||||||
if ( c == '\r' )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
buffer[count++] = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer[MIN(count, buffer_size - 1)] = 0;
|
|
||||||
|
|
||||||
return errno ? -1 : num_read;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Performance optimized version of the previous function. */
|
/* Performance optimized version of the previous function. */
|
||||||
int fast_readline(int fd, char *buf, int buf_size, void *parameters,
|
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)
|
||||||
}
|
}
|
||||||
#endif /* !defined(__PCTOOL__) */
|
#endif /* !defined(__PCTOOL__) */
|
||||||
|
|
||||||
|
/* Read (up to) a line of text from fd into buffer and return number of bytes
|
||||||
|
* read (which may be larger than the number of bytes stored in buffer). If
|
||||||
|
* an error occurs, -1 is returned (and buffer contains whatever could be
|
||||||
|
* read). A line is terminated by a LF char. Neither LF nor CR chars are
|
||||||
|
* stored in buffer.
|
||||||
|
*/
|
||||||
|
int read_line(int fd, char* buffer, int buffer_size)
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
int num_read = 0;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
|
||||||
|
while (count < buffer_size)
|
||||||
|
{
|
||||||
|
unsigned char c;
|
||||||
|
|
||||||
|
if (1 != read(fd, &c, 1))
|
||||||
|
break;
|
||||||
|
|
||||||
|
num_read++;
|
||||||
|
|
||||||
|
if ( c == '\n' )
|
||||||
|
break;
|
||||||
|
|
||||||
|
if ( c == '\r' )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
buffer[count++] = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer[MIN(count, buffer_size - 1)] = 0;
|
||||||
|
|
||||||
|
return errno ? -1 : num_read;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
char* skip_whitespace(char* const str)
|
char* skip_whitespace(char* const str)
|
||||||
{
|
{
|
||||||
char *s = str;
|
char *s = str;
|
||||||
|
|
|
@ -98,36 +98,6 @@ unsigned int htole32(unsigned int x)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int read_line(int fd, char* buffer, int buffer_size)
|
|
||||||
{
|
|
||||||
int count = 0;
|
|
||||||
int num_read = 0;
|
|
||||||
|
|
||||||
errno = 0;
|
|
||||||
|
|
||||||
while (count < buffer_size)
|
|
||||||
{
|
|
||||||
unsigned char c;
|
|
||||||
|
|
||||||
if (1 != read(fd, &c, 1))
|
|
||||||
break;
|
|
||||||
|
|
||||||
num_read++;
|
|
||||||
|
|
||||||
if ( c == '\n' )
|
|
||||||
break;
|
|
||||||
|
|
||||||
if ( c == '\r' )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
buffer[count++] = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer[MIN(count, buffer_size - 1)] = 0;
|
|
||||||
|
|
||||||
return errno ? -1 : num_read;
|
|
||||||
}
|
|
||||||
|
|
||||||
int recalc_dimension(struct dim *dst, struct dim *src)
|
int recalc_dimension(struct dim *dst, struct dim *src)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue