summaryrefslogtreecommitdiff
path: root/tools.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2005-11-04 17:18:33 +0100
committerKlaus Schmidinger <vdr@tvdr.de>2005-11-04 17:18:33 +0100
commit92af12daac8a33db8be0b33335bd79330ced9463 (patch)
tree32416d5ef4b5f96d09905d40c076a368fd275097 /tools.c
parent903e929a85945567e9433b93f03567fe2f3b98fc (diff)
downloadvdr-92af12daac8a33db8be0b33335bd79330ced9463.tar.gz
vdr-92af12daac8a33db8be0b33335bd79330ced9463.tar.bz2
cReadLine now dynamically allocates its buffer; changed cConfig::Load() to use cReadLine instead of a fixed buffer
Diffstat (limited to 'tools.c')
-rw-r--r--tools.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/tools.c b/tools.c
index e0a9ecf5..832f4293 100644
--- a/tools.c
+++ b/tools.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: tools.c 1.102 2005/11/04 14:26:39 kls Exp $
+ * $Id: tools.c 1.103 2005/11/04 16:33:18 kls Exp $
*/
#include "tools.h"
@@ -610,12 +610,24 @@ cString TimeString(time_t t)
// --- cReadLine -------------------------------------------------------------
+cReadLine::cReadLine(void)
+{
+ size = 0;
+ buffer = NULL;
+}
+
+cReadLine::~cReadLine()
+{
+ free(buffer);
+}
+
char *cReadLine::Read(FILE *f)
{
- if (fgets(buffer, sizeof(buffer), f) > 0) {
- int l = strlen(buffer) - 1;
- if (l >= 0 && buffer[l] == '\n')
- buffer[l] = 0;
+ int n = getline(&buffer, &size, f);
+ if (n > 0) {
+ n--;
+ if (buffer[n] == '\n')
+ buffer[n] = 0;
return buffer;
}
return NULL;