summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
authorAlexander Levin <al.le@rockbox.org>2009-06-24 15:18:32 +0000
committerAlexander Levin <al.le@rockbox.org>2009-06-24 15:18:32 +0000
commit763a7d74573dfc3ab2bff99332f00f8dec29cf0c (patch)
tree0b90731992aaa257d1be756cf7449f617488e50d /apps/plugins
parent095f417048950e1f2da8ee35192e8888481bb9ad (diff)
downloadrockbox-763a7d74573dfc3ab2bff99332f00f8dec29cf0c.zip
rockbox-763a7d74573dfc3ab2bff99332f00f8dec29cf0c.tar.gz
rockbox-763a7d74573dfc3ab2bff99332f00f8dec29cf0c.tar.bz2
rockbox-763a7d74573dfc3ab2bff99332f00f8dec29cf0c.tar.xz
Ensure that the file handle is always closed in text editor plugin (part of FS#10138 by Teruaki Kawashima, minor modifications by me)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21491 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/text_editor.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/apps/plugins/text_editor.c b/apps/plugins/text_editor.c
index 82c5e49..911b64e 100644
--- a/apps/plugins/text_editor.c
+++ b/apps/plugins/text_editor.c
@@ -136,31 +136,34 @@ char *list_get_name_cb(int selected_item, void* data,
else rb->strncpy(buf, b, buf_len);
return buf;
}
+
char filename[MAX_PATH];
int get_eol_string(char* fn)
{
- int fd=-1;
+ int fd, result;
char t;
- if (!fn)
- return 0;
- else if (!fn[0])
+
+ if (!fn || !fn[0])
return 0;
fd = rb->open(fn,O_RDONLY);
if (fd<0)
return 0;
+
eol[0] = '\0';
+ result = 1;
while (!eol[0])
{
if (!rb->read(fd,&t,1))
{
rb->strcpy(eol,"\n");
- return 0;
+ result = 0;
}
if (t == '\r')
{
if (rb->read(fd,&t,1) && t=='\n')
rb->strcpy(eol,"\r\n");
- else rb->strcpy(eol,"\r");
+ else
+ rb->strcpy(eol,"\r");
}
else if (t == '\n')
{
@@ -168,7 +171,7 @@ int get_eol_string(char* fn)
}
}
rb->close(fd);
- return 1;
+ return result;
}
void save_changes(int overwrite)