[evolution-data-server] Don't use getline, implement a simple replacement. Some systems don't have getline in their C librar
- From: Fridrich Strba <strba src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Don't use getline, implement a simple replacement. Some systems don't have getline in their C librar
- Date: Wed, 8 Sep 2010 20:45:28 +0000 (UTC)
commit f2a5566dd573d6819f6926c01a959f174174384d
Author: Fridrich Å trba <fridrich strba bluewin ch>
Date: Wed Sep 8 21:17:51 2010 +0200
Don't use getline, implement a simple replacement.
Some systems don't have getline in their C library, so use a private
implementation released under LGPL v2+ and found here:
http://www.google.com/codesearch/p?hl=en#qUwOD6iX2hc/openjaus/branches/tom/OpenJAUSv3.3.1/ojVehicleSim/src/getLine.c&q=getline%20lang:c&sa=N&cd=9&ct=rc&l=144
calendar/backends/file/Makefile.am | 1 -
calendar/backends/file/e-cal-backend-file.c | 62 ++++++++++++++++++++++++++-
2 files changed, 61 insertions(+), 2 deletions(-)
---
diff --git a/calendar/backends/file/Makefile.am b/calendar/backends/file/Makefile.am
index 6d86de2..c672157 100644
--- a/calendar/backends/file/Makefile.am
+++ b/calendar/backends/file/Makefile.am
@@ -40,7 +40,6 @@ test_interval_searches_LDADD = \
$(top_builddir)/calendar/libecal/libecal-1.2.la \
$(top_builddir)/calendar/libedata-cal/libedata-cal-1.2.la \
$(top_builddir)/libedataserver/libedataserver-1.2.la \
- libecalbackendfile.la \
$(EVOLUTION_CALENDAR_LIBS)
test_interval_searches_CPPFLAGS = \
diff --git a/calendar/backends/file/e-cal-backend-file.c b/calendar/backends/file/e-cal-backend-file.c
index 0ea7955..41f179e 100644
--- a/calendar/backends/file/e-cal-backend-file.c
+++ b/calendar/backends/file/e-cal-backend-file.c
@@ -1,9 +1,11 @@
/* Evolution calendar - iCalendar file backend
*
+ * Copyright (C) 1993 Free Software Foundation, Inc.
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
*
* Authors: Federico Mena-Quintero <federico ximian com>
* Rodrigo Moya <rodrigo ximian com>
+ * Jan Brittenson <bson gnu ai mit edu>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU Lesser General Public
@@ -3579,6 +3581,64 @@ static GOptionEntry entries[] =
{ NULL }
};
+/* Always add at least this many bytes when extending the buffer. */
+#define MIN_CHUNK 64
+
+static int
+private_getline (char **lineptr, size_t *n, FILE *stream)
+{
+ int nchars_avail;
+ char *read_pos;
+
+ if (!lineptr || !n || !stream)
+ return -1;
+
+ if (!*lineptr) {
+ *n = MIN_CHUNK;
+ *lineptr = (char *)malloc (*n);
+ if (!*lineptr)
+ return -1;
+ }
+
+ nchars_avail = (int) *n;
+ read_pos = *lineptr;
+
+ for (;;) {
+ int c = getc (stream);
+
+ if (nchars_avail < 2) {
+ if (*n > MIN_CHUNK)
+ *n *= 2;
+ else
+ *n += MIN_CHUNK;
+
+ nchars_avail = (int)(*n + *lineptr - read_pos);
+ *lineptr = (char *)realloc (*lineptr, *n);
+ if (!*lineptr)
+ return -1;
+ read_pos = *n - nchars_avail + *lineptr;
+ }
+
+ if (ferror (stream) || c == EOF) {
+ if (read_pos == *lineptr)
+ return -1;
+ else
+ break;
+ }
+
+ *read_pos++ = c;
+ nchars_avail--;
+
+ if (c == '\n')
+ /* Return the line. */
+ break;
+ }
+
+ *read_pos = '\0';
+
+ return (int)(read_pos - (*lineptr));
+}
+
int
main(int argc, char **argv)
{
@@ -3634,7 +3694,7 @@ main(int argc, char **argv)
fin = stdin;
}
- while ((read = getline(&line, &len, fin)) != -1) {
+ while ((read = private_getline(&line, &len, fin)) != -1) {
g_print ("Query %d: %s", num++, line);
if (only_execute)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]