/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* camel-stream-fs.c : file system based stream * * Authors: Bertrand Guiheneuf * Michael Zucchi * * Copyright 1999, 2000 Helix Code, Inc. (http://www.helixcode.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include #include "camel-seekable-substream.h" static CamelSeekableStreamClass *parent_class = NULL; /* Returns the class for a CamelSeekableSubStream */ #define CSS_CLASS(so) CAMEL_SEEKABLE_SUBSTREAM_CLASS (GTK_OBJECT(so)->klass) static int stream_read (CamelStream *stream, char *buffer, unsigned int n); static int stream_write (CamelStream *stream, const char *buffer, unsigned int n); static int stream_flush (CamelStream *stream); static int stream_close (CamelStream *stream); static gboolean eos (CamelStream *stream); static off_t stream_seek (CamelSeekableStream *stream, off_t offset, CamelStreamSeekPolicy policy); static void finalize (GtkObject *object); static void camel_seekable_substream_class_init (CamelSeekableSubstreamClass *camel_seekable_substream_class) { CamelSeekableStreamClass *camel_seekable_stream_class = CAMEL_SEEKABLE_STREAM_CLASS (camel_seekable_substream_class); CamelStreamClass *camel_stream_class = CAMEL_STREAM_CLASS (camel_seekable_substream_class); GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (camel_seekable_substream_class); parent_class = gtk_type_class (camel_seekable_stream_get_type ()); /* virtual method definition */ /* virtual method overload */ camel_stream_class->read = stream_read; camel_stream_class->write = stream_write; camel_stream_class->flush = stream_flush; camel_stream_class->close = stream_close; camel_stream_class->eos = eos; camel_seekable_stream_class->seek = stream_seek; gtk_object_class->finalize = finalize; } GtkType camel_seekable_substream_get_type (void) { static GtkType camel_seekable_substream_type = 0; if (!camel_seekable_substream_type) { GtkTypeInfo camel_seekable_substream_info = { "CamelSeekableSubstream", sizeof (CamelSeekableSubstream), sizeof (CamelSeekableSubstreamClass), (GtkClassInitFunc) camel_seekable_substream_class_init, (GtkObjectInitFunc) NULL, /* reserved_1 */ NULL, /* reserved_2 */ NULL, (GtkClassInitFunc) NULL, }; camel_seekable_substream_type = gtk_type_unique (camel_seekable_stream_get_type (), &camel_seekable_substream_info); } return camel_seekable_substream_type; } static void finalize (GtkObject *object) { CamelSeekableSubstream *seekable_substream = CAMEL_SEEKABLE_SUBSTREAM (object); if (seekable_substream->parent_stream) gtk_object_unref (GTK_OBJECT (seekable_substream->parent_stream)); GTK_OBJECT_CLASS (parent_class)->finalize (object); } /** * camel_seekable_substream_new_with_seekable_stream_and_bounds: * @parent_stream: a seekable parent stream * @inf_bound: a lower bound * @sup_bound: an upper bound * * Creates a new CamelSeekableSubstream that references the portion * of @parent_stream from @inf_bound to @sup_bound. (If @sup_bound is * #CAMEL_STREAM_UNBOUND, it references to the end of stream, even if * the stream grows.) * * While the substream is open, the caller cannot assume anything about * the current position of @parent_stream. After the substream has been * closed, @parent_stream will stabilize again. * * Return value: the substream **/ CamelStream * camel_seekable_substream_new_with_seekable_stream_and_bounds (CamelSeekableStream *parent_stream, off_t start, off_t end) { CamelSeekableSubstream *seekable_substream; g_return_val_if_fail (CAMEL_IS_SEEKABLE_STREAM (parent_stream), NULL); /* Create the seekable substream. */ seekable_substream = gtk_type_new (camel_seekable_substream_get_type ()); /* Initialize it. */ seekable_substream->parent_stream = parent_stream; gtk_object_ref (GTK_OBJECT (parent_stream)); /* Set the bound of the substream. We can ignore any possible error * here, because if we fail to seek now, it will try again later. */ camel_seekable_stream_set_bounds ((CamelSeekableStream *)seekable_substream, start, end); return CAMEL_STREAM (seekable_substream); } static gboolean parent_reset (CamelSeekableSubstream *seekable_substream, CamelSeekableStream *parent) { CamelSeekableStream *seekable_stream = CAMEL_SEEKABLE_STREAM (seekable_substream); if (camel_seekable_stream_tell (parent) == seekable_stream->position) return TRUE; return camel_seekable_stream_seek (parent, seekable_stream->position, CAMEL_STREAM_SET) == seekable_stream->position; } static int stream_read (CamelStream *stream, char *buffer, unsigned int n) { CamelSeekableStream *parent; CamelSeekableStream *seekable_stream = CAMEL_SEEKABLE_STREAM (stream); CamelSeekableSubstream *seekable_substream = CAMEL_SEEKABLE_SUBSTREAM (stream); int v; if (n == 0) return 0; parent = seekable_substream->parent_stream; /* Go to our position in the parent stream. */ if (!parent_reset (seekable_substream, parent)) { stream->eos = TRUE; return 0; } /* Compute how many bytes should be read. */ if (seekable_stream->bound_end != CAMEL_STREAM_UNBOUND) n = MIN (seekable_stream->bound_end - seekable_stream->position, n); if (n == 0) { stream->eos = TRUE; return 0; } v = camel_stream_read (CAMEL_STREAM (parent), buffer, n); /* ignore <0 - its an error, let the caller deal */ if (v > 0) seekable_stream->position += v; return v; } static int stream_write (CamelStream *stream, const char *buffer, unsigned int n) { /* NOT VALID ON SEEKABLE SUBSTREAM */ /* Well, its entirely valid, just not implemented */ g_warning ("CamelSeekableSubstream:: seekable substream doesn't " "have a write method yet?\n"); return -1; } static int stream_flush (CamelStream *stream) { /* NOT VALID ON SEEKABLE SUBSTREAM */ g_warning ("CamelSeekableSubstream:: seekable substream doesn't " "have a flush method\n"); return -1; } static int stream_close (CamelStream *stream) { /* we dont really want to close the substream ... */ return 0; } static gboolean eos (CamelStream *stream) { CamelSeekableSubstream *seekable_substream = CAMEL_SEEKABLE_SUBSTREAM (stream); CamelSeekableStream *seekable_stream = CAMEL_SEEKABLE_STREAM (stream); CamelSeekableStream *parent; gboolean eos; if (stream->eos) eos = TRUE; else { parent = seekable_substream->parent_stream; if (!parent_reset (seekable_substream, parent)) return TRUE; eos = camel_stream_eos (CAMEL_STREAM (parent)); if (!eos && (seekable_stream->bound_end != CAMEL_STREAM_UNBOUND)) { eos = seekable_stream->position >= seekable_stream->bound_end; } } return eos; } static off_t stream_seek (CamelSeekableStream *seekable_stream, off_t offset, CamelStreamSeekPolicy policy) { CamelSeekableSubstream *seekable_substream = CAMEL_SEEKABLE_SUBSTREAM (seekable_stream); CamelStream *stream = CAMEL_STREAM (seekable_stream); off_t real_offset = 0; stream->eos = FALSE; switch (policy) { case CAMEL_STREAM_SET: real_offset = offset; break; case CAMEL_STREAM_CUR: real_offset = seekable_stream->position + offset; break; case CAMEL_STREAM_END: real_offset = camel_seekable_stream_seek (seekable_substream->parent_stream, offset, CAMEL_STREAM_END); if (real_offset == -1) return -1; break; } if (seekable_stream->bound_end != CAMEL_STREAM_UNBOUND) real_offset = MIN (real_offset, seekable_stream->bound_end); if (real_offsetbound_start) real_offset = seekable_stream->bound_start; seekable_stream->position = real_offset; return real_offset; } ebsd-ports-gnome/commit/games?h=gnome-3.24&id=70bd26c5cbdd1a1f9071cdc3c0dd439a5335f656'>Remove expired ports:rene2015-06-118-191/+0 * games/golly:makc2015-06-109-183/+90 * games/dustrac:makc2015-06-106-26/+22 * - Fix shebangsamdmi32015-06-101-2/+4 * - Fix shebangsamdmi32015-06-101-2/+3 * - Fix shebangsamdmi32015-06-101-8/+9 * multimedia/libvpx: update to 1.4.0jbeich2015-06-091-0/+1 * - Actually disable sound support when SOUND option is disabledamdmi32015-06-091-1/+2 * - Modernize plistamdmi32015-06-083-35/+7 * - Modernize plistamdmi32015-06-082-5/+3 * - Update to 1.8.7amdmi32015-06-082-3/+3 * - Add LICENSE_FILEamdmi32015-06-082-9/+2 * - Switch to USES=autoreconfamdmi32015-06-071-4/+1 * games/openbor: update to r4163 snapshotjbeich2015-06-062-3/+3 * - Update to 1.0.1nemysis2015-06-061-1/+1 * - Update to 1.0.1nemysis2015-06-063-5/+25 * - Update to 1.82madpilot2015-06-0611-143/+86 * Update to Wolfpack Empire 4.3.33johans2015-06-065-35/+25 * - Fix BROKEN_powerpcamdmi32015-06-061-9/+4 * - Disable precompiled headers to fix build with old gcc on -current kernelamdmi32015-06-041-4/+11 * - Disable precompiled headers to fix build with old gcc on -current kernelamdmi32015-06-041-3/+12 * Update to version 1.5.1.danfe2015-06-032-3/+3 * Update to 1.05.000cs2015-06-032-4/+3 * - Drop maintainership by maintainer's requestamdmi32015-06-031-1/+1 * - Update to 1.1.4amdmi32015-06-022-3/+3 * - Update to git20150601amdmi32015-06-023-4/+15 * - Update to 0.3.3amdmi32015-06-022-4/+4 * Fix build on 9.x i386amdmi32015-06-021-0/+10 * - Update to 0.9amdmi32015-06-013-18/+35 * - Fix gemspec for rubygem-paint 1.0.0 updatesunpoet2015-06-012-1/+12 * games/2048-qt: cleanupsswills2015-06-011-2/+7 * - Update to version 1.8.6 [1]pawel2015-05-316-16/+19 * Cleanup USE_GITHUB usage.mat2015-05-3110-18/+16 * Update portaudio to v19/Remove portaudio2 [1]bapt2015-05-316-17/+112 * - Mark BROKEN, redeprecateamdmi32015-05-301-0/+4 * - Modernize plistamdmi32015-05-301-2/+1 * games/katawa-shoujo: slightly simplify distfilesjbeich2015-05-301-2/+2 * - Fix shebangsamdmi32015-05-291-4/+4 * - Unbreak, undeprecated, modernize plistamdmi32015-05-283-27/+40 * - Revert bogus games/springlobby removalamdmi32015-05-2711-0/+178 * - Fix shebangsamdmi32015-05-273-26/+31 * - Don't cat pkg-message from Makefilesamdmi32015-05-271-3/+0 * - Modernize plistamdmi32015-05-272-55/+1 * - Update to 2.44amdmi32015-05-273-10/+5 * - Update to 0.16.1amdmi32015-05-2713-309/+168 * - Drop @dirrm* from plistamdmi32015-05-261-2/+0 * - Add USES=desktop-file-utils as suggested by stage-qaamdmi32015-05-261-3/+3 * games/wesnoth: Revert version 1.13 => 1.12marino2015-05-263-11/+12 * - Update to 20150518wen2015-05-252-3/+3 * games/openra: update to 20150424jbeich2015-05-255-56/+127 * Remove $FreeBSD$ from patches files in categories a-j.mat2015-05-2252-132/+0 * - Fix build on pre-10.xamdmi32015-05-214-17/+15 * This is a GPL release of the Seven Kingdoms: Ancient Adversariesamdmi32015-05-215-0/+71 * - Modernize plistamdmi32015-05-212-33/+1 * - Drop @dirrm* from plistamdmi32015-05-212-12/+0 * - Drop @dirrm* from plistamdmi32015-05-201-5/+2 * Expire 14 gnome ports broken for more than 6 months (remove in 2 weeks)marino2015-05-202-0/+6 * - Drop @dirrm* from plistamdmi32015-05-192-5/+0 * games/kanatest: Mark BROKEN (runtime segfault)marino2015-05-191-0/+2 * Replace most occurences of github.com in MASTER_SITES with USE_GITHUB usage.mat2015-05-194-8/+8 * - Drop @dirrm* from plistamdmi32015-05-191-8/+0 * - Add CPE infoamdmi32015-05-161-1/+3 * games/supertux-devel:makc2015-05-166-73/+599 * Pyfa is a cross-platform desktop fitting application for EVE onlineamdmi32015-05-164-0/+64 * - Update to 1.13.0amdmi32015-05-163-11/+11 * - Switch to DISTVERSIONPREFIXamdmi32015-05-152-3/+3 * Wyrmsun is an open-source RTS game which features elements ofamdmi32015-05-155-0/+58 * Modified Stratagus engine for Wyrmsunamdmi32015-05-154-0/+77 * - Update to 0.2.8.3.3amdmi32015-05-143-25/+6 * - Add CPE infoamdmi32015-05-141-1/+1 * MASTER_SITES cleanup.mat2015-05-1496-167/+101 * - Drop @dirrm* from plistamdmi32015-05-142-5/+2 * - Drop @dirrm* from plistamdmi32015-05-141-93/+0 * - Bring back ONLY_FOR_ARCHS which was lost in the last updateamdmi32015-05-141-2/+11 * - Update to 2.3.0amdmi32015-05-1410-301/+1633 * - Update to 2.3.0amdmi32015-05-143-12/+20 * - Drop @dirrm* from plistamdmi32015-05-141-5/+0 * - Drop @dirrm* from plistamdmi32015-05-131-3/+0 * Update games/unnethack to 5.1.0-20131208knu2015-05-132-4/+3 * "Griel's Quest for the Sangraal" is a game released for MSX2 systemsamdmi32015-05-135-0/+89 * - Update to recent snapshot, switch to upstream github accountamdmi32015-05-132-5/+5 * - Update to 20150509amdmi32015-05-132-3/+3 * - Fix build on < 10.xamdmi32015-05-121-0/+4 * Cleanup DIST* variables.mat2015-05-1214-25/+19 * Fix RUN_DEPENDS after darkplaces updateantoine2015-05-121-1/+1 * Fix build on armv6lme2015-05-121-0/+4 * games/chessx: update 1.2.2 -> 1.3.2robak2015-05-104-18/+13 * - Enable all options by default to follow upstream and produce fully function...amdmi32015-05-101-14/+19 * - Take maintainership: I'm going to update these and port another stratagus-b...amdmi32015-05-092-2/+2 * - Add optional support for using newer libenet from portsamdmi32015-05-091-6/+19 * Fix build on 10.x and later.jkim2015-05-091-1/+1 * - Don't install static libraries with INSTALL_LIB (part 1/2)amdmi32015-05-082-3/+4 * games/katawa-shoujo: update to 1.3jbeich2015-05-083-7/+7 * - Drop @dirrm* from plistamdmi32015-05-081-1/+0 * - Fix WWWamdmi32015-05-081-1/+1 * - Fix build from non-rootamdmi32015-05-081-0/+3 * - Update to 0.4amdmi32015-05-082-5/+3 * games/childsplay: update to 2.6.5jbeich2015-05-072-4/+3 * - Fix broken keypad handling (mixed up keys)amdmi32015-05-072-1/+15 * games/darkplaces:makc2015-05-075-102/+67 * Update ports in the games category to not use GH_COMMIT.mat2015-05-0774-171/+116 * - Update to 4.6.0culot2015-05-053-3/+5 * games/oneko: unbreak install if locale-specific app-defaults dir existsjbeich2015-05-051-0/+23 * games/oneko: drop unnecessary indirection since do-patch disappearedjbeich2015-05-052-2/+1 * games/wxlauncher: add DEBUG option and put verbose logging behind itjbeich2015-05-051-2/+3 * games/wxlauncher: enable WX3 option by defaultjbeich2015-05-051-1/+2 * games/wxlauncher: unbreak WX3 option on DragonFly and FreeBSD 8.x/9.xjbeich2015-05-052-0/+13 * games/wxlauncher: unbreak build when WX3=on JOYSTICK=offjbeich2015-05-051-0/+13 * - Add USE_OCAML_CAMLP4 and USE_OCAML_TK to bsd.ocaml.mk which addmadpilot2015-05-041-1/+1 * - Allow staging as a regular userantoine2015-05-043-17/+6 * - Allow staging as a regular userantoine2015-05-042-20/+5 * games/wxlauncher: update to 0.9.6jbeich2015-05-042-18/+6 * games/assaultcube: unbreak on DragonFly and the package clusterjbeich2015-05-046-41/+36 * By request, reset maintainership of multiple portseadler2015-05-041-1/+1 * Allow staging as a regular userantoine2015-05-041-3/+2 * - Update to 0.045danilo2015-05-032-4/+3 * games/drcreep: update to 1.1jbeich2015-05-022-4/+3 * games/alephone-data: unbreak fetch and mark NO_ARCHjbeich2015-05-021-3/+2 * games/lincity: Fix build on gcc5marino2015-05-011-0/+29 * games/minecraft-server: Upgrade version 1.8.1 => 1.8.4marino2015-05-015-12/+18 * Remove expired ports:rene2015-04-3016-284/+0 * Properly track -lenet dependency after r285069jbeich2015-04-301-3/+3 * Fix build after const removal from iconv.madpilot2015-04-291-2/+11 * - Update to 1.2.6lme2015-04-283-43/+26 * - Clarify LICENSEamdmi32015-04-281-1/+1 * - Update to r4157 snapshotjbeich2015-04-254-44/+32 * Unbreak and upgrade to the latest availble version -- 0.98.mi2015-04-2540-610/+530 * Update to 20150424.adamw2015-04-253-3/+15 * - Add distfile mirroramdmi32015-04-251-1/+2 * - Postpone expiration, mi+thun@aldan.algebra.com has prepared update to 98.0,...amdmi32015-04-241-1/+1 * - Update to 0.6.0amdmi32015-04-2423-56/+824 * Stendhal is an open source 2D MMORPG with an excellent community. Players canamdmi32015-04-2411-0/+408 * - Fix broken communication with external tools (e.g. q2map): GtkRadiant'sdanfe2015-04-234-5/+43 * - Fix build on 64 bit architectures (cast from pointer to int loses precision)amdmi32015-04-232-45/+8 * - Fix build on 64 bit architectures (cast from pointer to int loses precision)amdmi32015-04-232-27/+5 * Make DragonFly use same headersjbeich2015-04-211-1/+1 * - Display a stage-qa warning when ports use PREFIX/var instead of /vartijl2015-04-214-31/+9 * Fix build when there is no /usr/bin/perl. (Also, say that this needs Perl format2015-04-202-5/+9 * Apply r379037 instead of trying to use C11's max_align_tjbeich2015-04-202-24/+39 * Fix build with Perl 5.21.1+mat2015-04-202-0/+38 * Derive CONFIGURE_TARGET check from OPSYS to fixjbeich2015-04-201-1/+1 * Unbreak build with gcc5 (and clang in future)jbeich2015-04-201-0/+24 * * Install HTML manual when DOCS option is enabledjbeich2015-04-201-3/+13 * Oops, incomplete version of the patch was committed in r384239.danfe2015-04-191-9/+31 * - Clang insists that reference cannot be bound to dereferenced null pointerdanfe2015-04-192-2/+58 * - Fix the build against modern libpng (do not try to access private data)danfe2015-04-195-32/+72 * - Remove libtool hacks and patches that are now handled by USES=libtooltijl2015-04-182-6/+0 * - Add CPE informationjbeich2015-04-171-1/+4 * - Improve previous patchamdmi32015-04-171-8/+4 * - Update to 1.12.2jbeich2015-04-172-3/+3 * - Update to 20150416jbeich2015-04-172-3/+3 * - Fix build on < 10.xamdmi32015-04-152-1/+7 * converters/libiconv:tijl2015-04-1510-63/+117 * Upgrade from 2.3.2 to 2.3.3. Define LICENSE.mi2015-04-152-4/+6 * Fix some glib schema issues.kwm2015-04-142-1/+3 * - Fix build on DragonFlyamdmi32015-04-145-0/+51 * In the 13th century, the Cathars, who preach about good Christianamdmi32015-04-145-0/+79 * - Update WWWamdmi32015-04-142-2/+3 * Typo: unbreak build if ENV is set for sh(1)jbeich2015-04-131-1/+1 * Add new port games/openborjbeich2015-04-136-0/+337 * - Add CPE infoamdmi32015-04-131-1/+1