set CHANGE make ly_set* functions return LY_ERR values

unify ly_set* function that were returning -1 as error indicator
combined with positive value indicating index inside the set. The most
of other libyang functions return LY_ERR to indicate result. The problem
of these functions was also the limited range of the returned index.
While internally index is uint32_t, it was limited only to a positive
part of int type.
diff --git a/src/printer_xml.c b/src/printer_xml.c
index 7ac4a1f..a90b012 100644
--- a/src/printer_xml.c
+++ b/src/printer_xml.c
@@ -59,45 +59,44 @@
 static const char *
 xml_print_ns(struct xmlpr_ctx *ctx, const char *ns, const char *new_prefix, uint32_t prefix_opts)
 {
-    int64_t i;
+    uint32_t i;
 
-    for (i = (int64_t)ctx->ns.count - 1; i > -1; --i) {
+    for (i = ctx->ns.count; i > 0; --i) {
         if (!new_prefix) {
             /* find default namespace */
-            if (!ctx->prefix.objs[i]) {
-                if (ctx->ns.objs[i] != ns) {
-                    /* different default namespace */
-                    i = -1;
+            if (!ctx->prefix.objs[i - 1]) {
+                if (ctx->ns.objs[i - 1] == ns) {
+                    /* matching default namespace */
+                    return ctx->prefix.objs[i - 1];
                 }
+                /* not matching default namespace */
                 break;
             }
         } else {
             /* find prefixed namespace */
-            if (ctx->ns.objs[i] == ns) {
-                if (!ctx->prefix.objs[i]) {
+            if (ctx->ns.objs[i - 1] == ns) {
+                if (!ctx->prefix.objs[i - 1]) {
                     /* default namespace is not interesting */
                     continue;
                 }
 
-                if (!strcmp(ctx->prefix.objs[i], new_prefix) || !(prefix_opts & LYXML_PREFIX_REQUIRED)) {
+                if (!strcmp(ctx->prefix.objs[i - 1], new_prefix) || !(prefix_opts & LYXML_PREFIX_REQUIRED)) {
                     /* the same prefix or can be any */
-                    break;
+                    return ctx->prefix.objs[i - 1];
                 }
             }
         }
     }
 
-    if (i == -1) {
-        /* suitable namespace not found, must be printed */
-        ly_print_(ctx->out, " xmlns%s%s=\"%s\"", new_prefix ? ":" : "", new_prefix ? new_prefix : "", ns);
+    /* suitable namespace not found, must be printed */
+    ly_print_(ctx->out, " xmlns%s%s=\"%s\"", new_prefix ? ":" : "", new_prefix ? new_prefix : "", ns);
 
-        /* and added into namespaces */
-        if (new_prefix) {
-            new_prefix = lydict_insert(ctx->ctx, new_prefix, 0);
-        }
-        ly_set_add(&ctx->prefix, (void *)new_prefix, LY_SET_OPT_USEASLIST);
-        i = ly_set_add(&ctx->ns, (void *)ns, LY_SET_OPT_USEASLIST);
+    /* and added into namespaces */
+    if (new_prefix) {
+        new_prefix = lydict_insert(ctx->ctx, new_prefix, 0);
     }
+    LY_CHECK_RET(ly_set_add(&ctx->prefix, (void *)new_prefix, LY_SET_OPT_USEASLIST, NULL), NULL);
+    LY_CHECK_RET(ly_set_add(&ctx->ns, (void *)ns, LY_SET_OPT_USEASLIST, &i), NULL);
 
     /* return it */
     return ctx->prefix.objs[i];