[gmime] Reduced code duplication



commit ac55fa4390ebe46bf360a70bc1a83006053c6bee
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date:   Fri Dec 15 10:28:25 2017 -0500

    Reduced code duplication

 gmime/gmime-stream-file.c |    8 +-------
 gmime/gmime-stream-fs.c   |    9 +--------
 gmime/gmime-stream-gio.c  |   12 +-----------
 gmime/gmime-stream-mmap.c |   20 +-------------------
 4 files changed, 4 insertions(+), 45 deletions(-)
---
diff --git a/gmime/gmime-stream-file.c b/gmime/gmime-stream-file.c
index e47058b..4f11414 100644
--- a/gmime/gmime-stream-file.c
+++ b/gmime/gmime-stream-file.c
@@ -373,7 +373,6 @@ stream_substream (GMimeStream *stream, gint64 start, gint64 end)
 GMimeStream *
 g_mime_stream_file_new (FILE *fp)
 {
-       GMimeStreamFile *fstream;
        gint64 start;
        
        g_return_val_if_fail (fp != NULL, NULL);
@@ -385,12 +384,7 @@ g_mime_stream_file_new (FILE *fp)
        if ((start = ftell (fp)) == -1)
                start = 0;
        
-       fstream = g_object_new (GMIME_TYPE_STREAM_FILE, NULL);
-       g_mime_stream_construct ((GMimeStream *) fstream, start, -1);
-       fstream->owner = TRUE;
-       fstream->fp = fp;
-       
-       return (GMimeStream *) fstream;
+       return g_mime_stream_file_new_with_bounds (fp, start, -1);
 }
 
 
diff --git a/gmime/gmime-stream-fs.c b/gmime/gmime-stream-fs.c
index f5b945f..7ded4b0 100644
--- a/gmime/gmime-stream-fs.c
+++ b/gmime/gmime-stream-fs.c
@@ -424,7 +424,6 @@ stream_substream (GMimeStream *stream, gint64 start, gint64 end)
 GMimeStream *
 g_mime_stream_fs_new (int fd)
 {
-       GMimeStreamFs *fs;
        gint64 start;
        
 #ifdef G_OS_WIN32
@@ -434,13 +433,7 @@ g_mime_stream_fs_new (int fd)
        if ((start = lseek (fd, (off_t) 0, SEEK_CUR)) == -1)
                start = 0;
        
-       fs = g_object_new (GMIME_TYPE_STREAM_FS, NULL);
-       g_mime_stream_construct ((GMimeStream *) fs, start, -1);
-       fs->owner = TRUE;
-       fs->eos = FALSE;
-       fs->fd = fd;
-       
-       return (GMimeStream *) fs;
+       return g_mime_stream_fs_new_with_bounds (fd, start, -1);
 }
 
 
diff --git a/gmime/gmime-stream-gio.c b/gmime/gmime-stream-gio.c
index 446c336..a19a8cb 100644
--- a/gmime/gmime-stream-gio.c
+++ b/gmime/gmime-stream-gio.c
@@ -630,17 +630,7 @@ stream_substream (GMimeStream *stream, gint64 start, gint64 end)
 GMimeStream *
 g_mime_stream_gio_new (GFile *file)
 {
-       GMimeStreamGIO *gio;
-       
-       g_return_val_if_fail (G_IS_FILE (file), NULL);
-       
-       gio = g_object_new (GMIME_TYPE_STREAM_GIO, NULL);
-       g_mime_stream_construct ((GMimeStream *) gio, 0, -1);
-       gio->file = file;
-       gio->owner = TRUE;
-       gio->eos = FALSE;
-       
-       return (GMimeStream *) gio;
+       return g_mime_stream_gio_new_with_bounds (file, 0, -1);
 }
 
 
diff --git a/gmime/gmime-stream-mmap.c b/gmime/gmime-stream-mmap.c
index 6746a46..e99ae18 100644
--- a/gmime/gmime-stream-mmap.c
+++ b/gmime/gmime-stream-mmap.c
@@ -382,30 +382,12 @@ GMimeStream *
 g_mime_stream_mmap_new (int fd, int prot, int flags)
 {
 #ifdef HAVE_MMAP
-       GMimeStreamMmap *mm;
-       struct stat st;
        gint64 start;
-       char *map;
        
        if ((start = lseek (fd, 0, SEEK_CUR)) == -1)
                return NULL;
        
-       if (fstat (fd, &st) == -1)
-               return NULL;
-       
-       map = mmap (NULL, st.st_size, prot, flags, fd, 0);
-       if (map == MAP_FAILED)
-               return NULL;
-       
-       mm = g_object_new (GMIME_TYPE_STREAM_MMAP, NULL);
-       g_mime_stream_construct ((GMimeStream *) mm, start, -1);
-       mm->owner = TRUE;
-       mm->eos = FALSE;
-       mm->fd = fd;
-       mm->map = map;
-       mm->maplen = st.st_size;
-       
-       return (GMimeStream *) mm;
+       return g_mime_stream_mmap_new_with_bounds (fd, prot, flags, start, -1);
 #else
        return NULL;
 #endif /* HAVE_MMAP */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]