tFunction to retrieve torrent size - libeech - bittorrent library
 (HTM) git clone git://z3bra.org/libeech.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit ba84409915193ec48b1becfaf434e3a1ba780628
 (DIR) parent 1f684681b6e996a18378c7567a1fa0b1fe903a45
 (HTM) Author: z3bra <contactatz3bradotorg>
       Date:   Thu, 19 Oct 2017 00:13:33 +0200
       
       Function to retrieve torrent size
       
       Diffstat:
         M libeech.c                           |      29 +++++++++++++++++++++++++++++
       
       1 file changed, 29 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/libeech.c b/libeech.c
       t@@ -18,6 +18,7 @@
        /* helpers to retrieve attributes from metadata */
        static char * peerid();
        static unsigned char * infohash(struct torrent *);
       +static long torrentsize(struct torrent *);
        
        /* Initialization of the torrent struct */
        static int loadfile(struct torrent *, char *);
       t@@ -59,6 +60,34 @@ infohash(struct torrent *t)
                return hash;
        }
        
       +/* Calculate full torrent size */
       +static long
       +torrentsize(struct torrent *t)
       +{
       +        int i;
       +        long l, sz = 0;
       +        struct be info, f, v;
       +
       +        if (bekv(&t->be, "info", 4, &info) < 0)
       +                return -1;
       +        if (!bekv(&info, "files", 5, &f)) {
       +                for (i = 0; !belistnext(&f) && !belistover(&f); i++) {
       +                        if (bekv(&f, "length", 6, &v) < 0)
       +                                return -1;
       +                        if (beint(&v, &l) < 0)
       +                                return -1;
       +                        sz += l;
       +                }
       +        } else {
       +                if (bekv(&info, "length", 6, &v) < 0)
       +                        return -1;
       +                if (beint(&v, &sz) < 0)
       +                        return -1;
       +        }
       +
       +        return sz;
       +}
       +
        /* Read torrent file into a memory buffer */
        static int
        loadfile(struct torrent *t, char *path)