forked from len0rd/rockbox
Unify opening of utf-8 files (FS#6203). This also adds ignoring the BOM in several places it has been missing (as FS#6071).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18185 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
6485d6d3ba
commit
02103a2fa7
8 changed files with 55 additions and 54 deletions
31
apps/misc.c
31
apps/misc.c
|
@ -1154,7 +1154,7 @@ char *strip_extension(char* buffer, int buffer_size, const char *filename)
|
|||
{
|
||||
char *dot = strrchr(filename, '.');
|
||||
int len;
|
||||
|
||||
|
||||
if (buffer_size <= 0)
|
||||
{
|
||||
return NULL;
|
||||
|
@ -1180,6 +1180,35 @@ char *strip_extension(char* buffer, int buffer_size, const char *filename)
|
|||
}
|
||||
#endif /* !defined(__PCTOOL__) */
|
||||
|
||||
/** Open a UTF-8 file and set file descriptor to first byte after BOM.
|
||||
* If no BOM is present this behaves like open().
|
||||
* If the file is opened for writing and O_TRUNC is set, write a BOM to
|
||||
* the opened file and leave the file pointer set after the BOM.
|
||||
*/
|
||||
int open_utf8(const char* pathname, int flags)
|
||||
{
|
||||
int fd;
|
||||
unsigned char bom[BOM_SIZE];
|
||||
|
||||
fd = open(pathname, flags);
|
||||
if(fd < 0)
|
||||
return fd;
|
||||
|
||||
if(flags & (O_TRUNC | O_WRONLY))
|
||||
{
|
||||
write(fd, BOM, BOM_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
read(fd, bom, BOM_SIZE);
|
||||
/* check for BOM */
|
||||
if(memcmp(bom, BOM, BOM_SIZE))
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_LCD_COLOR
|
||||
/*
|
||||
* Helper function to convert a string of 6 hex digits to a native colour
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue