From 763a7d74573dfc3ab2bff99332f00f8dec29cf0c Mon Sep 17 00:00:00 2001 From: Alexander Levin Date: Wed, 24 Jun 2009 15:18:32 +0000 Subject: [PATCH] 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 --- apps/plugins/text_editor.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/apps/plugins/text_editor.c b/apps/plugins/text_editor.c index 82c5e49632..911b64e7ab 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)