From bc3d8eef39b53522f04eaea0d68308a299b1c9ce Mon Sep 17 00:00:00 2001 From: Alexander Vdolainen Date: Mon, 22 Feb 2016 03:32:11 +0200 Subject: [PATCH] [examples] streamfl* bugfixes; --- examples/streamflc.c | 6 +++++- examples/streamfld.c | 14 +++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/examples/streamflc.c b/examples/streamflc.c index c4f8009..52ac4d6 100644 --- a/examples/streamflc.c +++ b/examples/streamflc.c @@ -135,7 +135,7 @@ static int __dirlist(FILE *f, struct _remote_host *remote, struct _astream *rstr rstream->print_head(f); - stream = sxstream_open(link, opt, stream_tid, SXE_O_READ | SXE_O_TRUNC); + stream = sxstream_open(link, opt, stream_tid, SXE_O_READ); if(!stream) { fprintf(stderr, "Failed to open stream with %d ID (%d).\n", stream_tid, errno); return EINVAL; @@ -144,6 +144,10 @@ static int __dirlist(FILE *f, struct _remote_host *remote, struct _astream *rstr while((list = sxstream_read(stream)) != NULL) rstream->print_op(f, list); + if(errno != SXE_EOS) { + fprintf(stderr, "Reading failed (%d)\n", errno); + } + sxstream_close(stream); return 0; diff --git a/examples/streamfld.c b/examples/streamfld.c index 88eab3a..6fe9406 100644 --- a/examples/streamfld.c +++ b/examples/streamfld.c @@ -183,13 +183,17 @@ static size_t dirlist_read(struct sxstream_opened *stream, size_t sz, uint64_t o list_head_t *llist_prev = sxstream_opened_getelist(stream); list_head_t *llist_new = NULL; - if(!pslist || !llist_new) return -1; + if(!pslist) return -1; /* read and fill new list */ - if(readdir_r(pslist->dp, &(pslist->dent), &(pslist->dres))) - return -1; + if(readdir_r(pslist->dp, &(pslist->dent), &(pslist->dres))) return -1; + /* if finished return 0 */ - if(!pslist->dres) return 0; + if(!pslist->dres) { + if(llist_prev) sxstream_generic_slist_free(llist_prev); + stream->ent_buf = NULL; + return 0; + } /* allocate a new */ if(!(llist_new = sxstream_generic_slist_alloc())) return -1; else { /* fill this list */ @@ -202,7 +206,7 @@ static size_t dirlist_read(struct sxstream_opened *stream, size_t sz, uint64_t o goto __fail; } /* otherwise destroy last list */ - sxstream_generic_slist_free(llist_prev); + if(llist_prev) sxstream_generic_slist_free(llist_prev); *rlist = llist_new; /* assign new list */ return 1;