From 12710a075c4f01bc927e2d24e1b031d3854f2026 Mon Sep 17 00:00:00 2001 From: short <> Date: Thu, 12 Dec 2002 03:59:22 +0000 Subject: [PATCH] +captive_giochannel_size(): detect 'GIOChannel' file/device size --- src/libcaptive/storage/Makefile.am | 3 +- src/libcaptive/storage/size.c | 74 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 src/libcaptive/storage/size.c diff --git a/src/libcaptive/storage/Makefile.am b/src/libcaptive/storage/Makefile.am index a1a09e0..78e1c81 100644 --- a/src/libcaptive/storage/Makefile.am +++ b/src/libcaptive/storage/Makefile.am @@ -21,4 +21,5 @@ include $(top_srcdir)/src/libcaptive/Makefile-libcaptive.am noinst_LTLIBRARIES=libstorage.la libstorage_la_SOURCES= \ - cdrom.c + cdrom.c \ + size.c diff --git a/src/libcaptive/storage/size.c b/src/libcaptive/storage/size.c new file mode 100644 index 0000000..47948e9 --- /dev/null +++ b/src/libcaptive/storage/size.c @@ -0,0 +1,74 @@ +/* $Id$ + * Detect media size of given GIOChannel for libcaptive + * Copyright (C) 2002 Jan Kratochvil + * + * 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; exactly version 2 of June 1991 is required + * + * 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 "config.h" + +#include "captive/storage.h" /* self */ +#include +#include + + +guint64 captive_giochannel_size(GIOChannel *iochannel) +{ +gint fd; +gint64 low,high,mid; +GIOStatus erriostatus; +gchar bufchar; +gsize bufchargot; + + g_return_val_if_fail(iochannel!=NULL,0); + + fd=g_io_channel_unix_get_fd(iochannel); + g_return_val_if_fail(fd!=-1,0); + + /* FIXME: TODO: ioctl() detection */ + + /* low ==high: low (high) + * low+1==high: mid==low; NORMAL: no change: high + * low+1==high: mid==low; EOF : high=mid => 'low==high' case + */ + for (low=0, + high= + G_MAXINT; /* FIXME: 'G_MAXINT64' fails on g_io_channel_seek_position() */ + low+1=0); + return high; +} -- 1.8.3.1