]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libndr: Simplify indentation in ndr_print
authorVolker Lendecke <vl@samba.org>
Sat, 7 Jun 2025 09:34:18 +0000 (11:34 +0200)
committerMartin Schwenke <martins@samba.org>
Sat, 14 Jun 2025 08:46:34 +0000 (08:46 +0000)
printf can take care of the for-loop

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Martin Schwenke <martin@meltin.net>
librpc/ndr/ndr.c
librpc/ndr/ndr_dnsp.c
source4/librpc/ndr/py_xattr.c

index 896f682d2c288d097fb75158bce798bfdae1f59a..082bacc2fa6f42577b3b8157f9a0775b2cdbc780 100644 (file)
@@ -305,7 +305,6 @@ _PUBLIC_ void ndr_print_debugc_helper(struct ndr_print *ndr, const char *format,
 {
        va_list ap;
        char *s = NULL;
-       uint32_t i;
        int ret;
        int dbgc_class;
 
@@ -325,11 +324,7 @@ _PUBLIC_ void ndr_print_debugc_helper(struct ndr_print *ndr, const char *format,
                return;
        }
 
-       for (i=0;i<ndr->depth;i++) {
-               DEBUGADDC(dbgc_class, 1,("    "));
-       }
-
-       DEBUGADDC(dbgc_class, 1,("%s\n", s));
+       DEBUGADDC(dbgc_class, 1, ("%*.s\n", 4 * ndr->depth, s));
        free(s);
 }
 
@@ -337,7 +332,6 @@ _PUBLIC_ void ndr_print_debug_helper(struct ndr_print *ndr, const char *format,
 {
        va_list ap;
        char *s = NULL;
-       uint32_t i;
        int ret;
 
        va_start(ap, format);
@@ -354,23 +348,16 @@ _PUBLIC_ void ndr_print_debug_helper(struct ndr_print *ndr, const char *format,
                return;
        }
 
-       for (i=0;i<ndr->depth;i++) {
-               DEBUGADD(1,("    "));
-       }
-
-       DEBUGADD(1,("%s\n", s));
+       DEBUGADD(1, ("%*.s%s\n", 4 * ndr->depth, "", s));
        free(s);
 }
 
 _PUBLIC_ void ndr_print_printf_helper(struct ndr_print *ndr, const char *format, ...)
 {
        va_list ap;
-       uint32_t i;
 
        if (!ndr->no_newline) {
-               for (i=0;i<ndr->depth;i++) {
-                       printf("    ");
-               }
+               printf("%*.s", 4 * ndr->depth, "");
        }
 
        va_start(ap, format);
@@ -384,13 +371,12 @@ _PUBLIC_ void ndr_print_printf_helper(struct ndr_print *ndr, const char *format,
 _PUBLIC_ void ndr_print_string_helper(struct ndr_print *ndr, const char *format, ...)
 {
        va_list ap;
-       uint32_t i;
 
        if (!ndr->no_newline) {
-               for (i=0;i<ndr->depth;i++) {
-                       ndr->private_data = talloc_asprintf_append_buffer(
-                               (char *)ndr->private_data, "    ");
-               }
+               talloc_asprintf_addbuf((char **)&ndr->private_data,
+                                      "%*.s",
+                                      ndr->depth * 4,
+                                      "");
        }
 
        va_start(ap, format);
@@ -398,8 +384,7 @@ _PUBLIC_ void ndr_print_string_helper(struct ndr_print *ndr, const char *format,
                                                    format, ap);
        va_end(ap);
        if (!ndr->no_newline) {
-               ndr->private_data = talloc_asprintf_append_buffer((char *)ndr->private_data,
-                                                                 "\n");
+               talloc_asprintf_addbuf((char **)&ndr->private_data, "\n");
        }
 }
 
index 2f218edade4e681ea5f42c8ca8eca38c7741ac31..43efa3466d78862a6007e6e9d80c7fe4d3818abf 100644 (file)
@@ -193,10 +193,7 @@ _PUBLIC_ void ndr_print_dnsp_string_list(struct ndr_print *ndr, const char *name
        uint32_t i;
 
        ndr->no_newline = true;
-       for (i=0; i<ndr->depth; i++) {
-               ndr->print(ndr, "    ");
-       }
-       ndr->print(ndr, "%-25s:", name);
+       ndr->print(ndr, "%*.s%-25s:", 4 * ndr->depth, "", name);
        for (i=0; i<list->count; i++) {
                ndr->print(ndr, " \"%s\"", list->str[i]);
        }
index 523c1ab4a193a44ebaa70bb3f75570353761707b..df134e01a9ab7214e8f2f63498c85d5cfdd02183 100644 (file)
@@ -44,7 +44,7 @@ static void ntacl_print_debug_helper(struct ndr_print *ndr, const char *format,
 {
         va_list ap;
         char *s = NULL;
-        int i, ret;
+        int ret;
 
         va_start(ap, format);
         ret = vasprintf(&s, format, ap);
@@ -54,11 +54,8 @@ static void ntacl_print_debug_helper(struct ndr_print *ndr, const char *format,
                return;
        }
 
-        for (i=0;i<ndr->depth;i++) {
-                printf("    ");
-        }
+       printf("%*.s\n", 4 * ndr->depth, s);
 
-        printf("%s\n", s);
         free(s);
 }