diff --git a/lib/stream.c b/lib/stream.c index 146758a..21a1e32 100644 --- a/lib/stream.c +++ b/lib/stream.c @@ -53,7 +53,7 @@ static int __flag_check(int s_flag, int d_flag) { int i; - for(i = 1; i < 7; i++) + for(i = 1; i < 6; i++) if((d_flag & (1 << i)) && !(s_flag & (1 << i))) return 1; return 0; @@ -100,7 +100,7 @@ static sxstream_t *__stream_open(sxlink_t *link, sxchnl_t *channel, const char * if(r != SXE_RAPIDMSG) { errno = r; goto __fini; - } + } else r = 0; /* time to get the special id, put it to the link and clean up all */ buf = sxmsg_rapidbuf(msg); @@ -117,7 +117,6 @@ static sxstream_t *__stream_open(sxlink_t *link, sxchnl_t *channel, const char * if(idx && idx < 2) sid = strtoul(isx->val, NULL, 0); if(idx >= 2) r = SXE_BADPROTO; } - destroy_sexp(sx); if(!r) { @@ -186,10 +185,12 @@ sxstream_t *sxstream_open(sxlink_t *link, const char *opt, int stid, int flags) flags |= SXE_O_OCHANNELED; ss = __stream_open(link, channel, opt, s_desc, stid, flags); + r = errno; __fini: - errno = r; + if(r) errno = r; if(!ss && channel) sxchannel_close(channel); + errno = r; return ss; } @@ -219,7 +220,7 @@ sxstream_t *sxstream_openwch(sxlink_t *link, sxchnl_t *channel, const char *opt, ss = __stream_open(link, channel, opt, s_desc, stid, flags); __fini: - errno = r; + if(r) errno = r; return ss; } @@ -430,7 +431,7 @@ list_head_t *sxstream_read(sxstream_t *stream) } else list_add2tail(stream->entries, &listentry->node); SEXP_ITERATE_LIST(isx, iisx, iidx) { - if(isx->ty == SEXP_LIST) goto __badproto; + if(iisx->ty == SEXP_LIST) goto __badproto; if(!(entry = __alloc_entry((const char *)iisx->val))) goto __enomem; else list_add2tail(listentry->list, &entry->node); } @@ -564,7 +565,7 @@ int _builtin_stream_open(void *m, sexp_t *sx) default: goto __badproto; break; } } - } else goto __badproto; + } else if(idx) goto __badproto; } /* check availability */