diff options
author | JP Rosevear <jpr@ximian.com> | 2004-02-02 22:48:24 +0800 |
---|---|---|
committer | JP Rosevear <jpr@src.gnome.org> | 2004-02-02 22:48:24 +0800 |
commit | bf713af029d3e4411367a0dd26f9e343853a32ae (patch) | |
tree | 2efab369acba276520ed803af6ee2d4c9191a89b /calendar | |
parent | fba0a4acade67620df6c55830b6b5e92a96e1287 (diff) | |
download | gsoc2013-evolution-bf713af029d3e4411367a0dd26f9e343853a32ae.tar.gz gsoc2013-evolution-bf713af029d3e4411367a0dd26f9e343853a32ae.tar.zst gsoc2013-evolution-bf713af029d3e4411367a0dd26f9e343853a32ae.zip |
use g_file_get_contents (load_file_fn): ditto (vcal_support_format_fn):
2004-02-02 JP Rosevear <jpr@ximian.com>
* importers/icalendar-importer.c (support_format_fn): use
g_file_get_contents
(load_file_fn): ditto
(vcal_support_format_fn): ditto
(load_vcalendar_file): ditto
svn path=/trunk/; revision=24568
Diffstat (limited to 'calendar')
-rw-r--r-- | calendar/ChangeLog | 8 | ||||
-rw-r--r-- | calendar/importers/icalendar-importer.c | 81 |
2 files changed, 24 insertions, 65 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog index c49e621148..257e866430 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,11 @@ +2004-02-02 JP Rosevear <jpr@ximian.com> + + * importers/icalendar-importer.c (support_format_fn): use + g_file_get_contents + (load_file_fn): ditto + (vcal_support_format_fn): ditto + (load_vcalendar_file): ditto + 2004-01-30 JP Rosevear <jpr@ximian.com> * remove dead files diff --git a/calendar/importers/icalendar-importer.c b/calendar/importers/icalendar-importer.c index c1b237e0d5..baeab1e70d 100644 --- a/calendar/importers/icalendar-importer.c +++ b/calendar/importers/icalendar-importer.c @@ -80,47 +80,6 @@ importer_destroy_cb (gpointer user_data) g_free (ici); } -/* This reads in an entire file and returns it. It returns NULL on error. - The returned string should be freed. */ -static char* -read_file (const char *filename) -{ - int fd, n; - GString *str; - char buffer[2049]; - gboolean error = FALSE; - - /* read file contents */ - fd = open (filename, O_RDONLY); - if (fd == -1) - return NULL; - - str = g_string_new (""); - while (1) { - memset (buffer, 0, sizeof(buffer)); - n = read (fd, buffer, sizeof (buffer) - 1); - if (n > 0) { - str = g_string_append (str, buffer); - } else if (n == 0) { - break; - } else { - error = TRUE; - break; - } - } - - close (fd); - - if (error) { - g_string_free (str, FALSE); - return NULL; - } else { - gchar *retval = str->str; - g_string_free (str, FALSE); - return retval; - } -} - /* This removes all components except VEVENTs and VTIMEZONEs from the toplevel icalcomponent, and returns a GList of the VTODO components. */ static GList* @@ -309,15 +268,15 @@ support_format_fn (EvolutionImporter *importer, const char *filename, void *closure) { - char *contents; + char *contents ; icalcomponent *icalcomp; gboolean ret = FALSE; - contents = read_file (filename); - - /* parse the file */ - if (contents) { + if (g_file_get_contents (filename, &contents, NULL, NULL)) { + /* parse the file */ icalcomp = icalparser_parse_string (contents); + g_free (contents); + if (icalcomp) { if (icalcomponent_is_valid (icalcomp)) ret = TRUE; @@ -327,8 +286,6 @@ support_format_fn (EvolutionImporter *importer, } } - g_free (contents); - return ret; } @@ -345,8 +302,6 @@ load_file_fn (EvolutionImporter *importer, g_return_val_if_fail (ici != NULL, FALSE); - contents = read_file (filename); - if (!strcmp (folder_type, "calendar")) { ici->folder_contains_events = TRUE; ici->folder_contains_tasks = FALSE; @@ -359,11 +314,14 @@ load_file_fn (EvolutionImporter *importer, f = g_strdup ("tasks.ics"); } - /* parse the file */ - if (contents) { + + if (g_file_get_contents (filename, &contents, NULL, NULL)) { icalcomponent *icalcomp; + /* parse the file */ icalcomp = icalparser_parse_string (contents); + g_free (contents); + if (icalcomp) { char *real_uri; @@ -389,7 +347,6 @@ load_file_fn (EvolutionImporter *importer, } } - g_free (contents); g_free (f); return ret; @@ -429,13 +386,12 @@ vcal_support_format_fn (EvolutionImporter *importer, char *contents; gboolean ret = FALSE; - contents = read_file (filename); - - /* parse the file */ - if (contents) { + if (g_file_get_contents (filename, &contents, NULL, NULL)) { VObject *vcal; + /* parse the file */ vcal = Parse_MIME (contents, strlen (contents)); + g_free (contents); if (vcal) { icalcomponent *icalcomp; @@ -451,8 +407,6 @@ vcal_support_format_fn (EvolutionImporter *importer, } } - g_free (contents); - return ret; } @@ -469,13 +423,12 @@ load_vcalendar_file (const char *filename) defaults.alarm_audio_fmttype = "audio/x-wav"; defaults.alarm_description = (char*) _("Reminder!!"); - contents = read_file (filename); - - /* parse the file */ - if (contents) { + if (g_file_get_contents (filename, &contents, NULL, NULL)) { VObject *vcal; + /* parse the file */ vcal = Parse_MIME (contents, strlen (contents)); + g_free (contents); if (vcal) { icalcomp = icalvcal_convert_with_defaults (vcal, @@ -484,8 +437,6 @@ load_vcalendar_file (const char *filename) } } - g_free (contents); - return icalcomp; } |