static GMimeStream *
stream_substream (GMimeStream *stream, gint64 start, gint64 end)
{
	GMimeStreamFile *fstream;
	
	fstream = g_object_newv (GMIME_TYPE_STREAM_FILE, 0, NULL);
	g_mime_stream_construct (GMIME_STREAM (fstream), start, end);
	fstream->owner = FALSE;
	fstream->fp = GMIME_STREAM_FILE (stream)->fp;
	
	return GMIME_STREAM (fstream);
}
/**
 * g_mime_stream_file_new_with_bounds:
 * @fp: a FILE pointer
 * @start: start boundary
 * @end: end boundary
 *
 * Creates a new #GMimeStreamFile object around @fp with bounds @start
 * and @end.
 *
 * Note: The created #GMimeStreamFile object will own the FILE pointer
 * passed in.
 *
 * Returns: a stream using @fp with bounds @start and @end.
 **/
GMimeStream *
g_mime_stream_file_new_with_bounds (FILE *fp, gint64 start, gint64 end)
{
	GMimeStreamFile *fstream;
	
	g_return_val_if_fail (fp != NULL, NULL);
	
#ifdef G_OS_WIN32
	_setmode (_fileno (fp), O_BINARY);
#endif
	
	fstream = g_object_newv (GMIME_TYPE_STREAM_FILE, 0, NULL);
	g_mime_stream_construct (GMIME_STREAM (fstream), start, end);
	fstream->owner = TRUE;
	fstream->fp = fp;
	
	return GMIME_STREAM (fstream);
}
Beispiel #3
0
static GMimeStream *
lbmss_stream_substream(GMimeStream * stream, gint64 start, gint64 end)
{
    LibBalsaMimeStreamShared *stream_shared;
    GMimeStreamFs *fstream;

    stream_shared =
        g_object_new(LIBBALSA_TYPE_MIME_STREAM_SHARED, NULL, NULL);
    stream_shared->lock =
        lbmss_lock_ref(LIBBALSA_MIME_STREAM_SHARED(stream)->lock);

    fstream = GMIME_STREAM_FS(stream_shared);
    fstream->owner = FALSE;
    fstream->fd = GMIME_STREAM_FS(stream)->fd;
    g_mime_stream_construct(GMIME_STREAM(fstream), start, end);

    return GMIME_STREAM(fstream);
}
Beispiel #4
0
/**
 * libbalsa_mime_stream_shared_new:
 * @fd: file descriptor
 *
 * Create a new GMimeStreamShared object around @fd.
 *
 * Returns a stream using @fd.
 *
 **/
GMimeStream *
libbalsa_mime_stream_shared_new(int fd)
{
    LibBalsaMimeStreamShared *stream_shared;
    GMimeStreamFs *fstream;
    gint64 start;

    stream_shared =
        g_object_new(LIBBALSA_TYPE_MIME_STREAM_SHARED, NULL, NULL);
    stream_shared->lock = lbmss_lock_new();

    fstream = GMIME_STREAM_FS(stream_shared);
    fstream->owner = TRUE;
    fstream->eos = FALSE;
    fstream->fd = fd;

    start = lseek(fd, 0, SEEK_CUR);
    g_mime_stream_construct(GMIME_STREAM(fstream), start, -1);

    return GMIME_STREAM(fstream);
}
/**
 * g_mime_stream_file_new:
 * @fp: a FILE pointer
 *
 * Creates a new #GMimeStreamFile object around @fp.
 *
 * Note: The created #GMimeStreamFile object will own the FILE pointer
 * passed in.
 *
 * Returns: a stream using @fp.
 **/
GMimeStream *
g_mime_stream_file_new (FILE *fp)
{
	GMimeStreamFile *fstream;
	gint64 start;
	
	g_return_val_if_fail (fp != NULL, NULL);
	
#ifdef G_OS_WIN32
	_setmode (_fileno (fp), O_BINARY);
#endif
	
	if ((start = ftell (fp)) == -1)
		start = 0;
	
	fstream = g_object_newv (GMIME_TYPE_STREAM_FILE, 0, NULL);
	g_mime_stream_construct (GMIME_STREAM (fstream), start, -1);
	fstream->owner = TRUE;
	fstream->fp = fp;
	
	return GMIME_STREAM (fstream);
}
static GMimeStream *
stream_substream (GMimeStream *stream, gint64 start, gint64 end)
{
	/* FIXME: maybe we should return a GMimeStreamFs? */
	GMimeStreamMmap *mstream;
	
	mstream = g_object_newv (GMIME_TYPE_STREAM_MMAP, 0, NULL);
	g_mime_stream_construct (GMIME_STREAM (mstream), start, end);
	mstream->fd = GMIME_STREAM_MMAP (stream)->fd;
	mstream->owner = FALSE;
	
	mstream->maplen = GMIME_STREAM_MMAP (stream)->maplen;
	mstream->map = GMIME_STREAM_MMAP (stream)->map;
	
	return (GMimeStream *) mstream;
}