Whamcloud - gitweb
LU-13855 tests: remove the need for libiberty
[fs/lustre-release.git] / lustre / tests / statx.c
index eff64f8..d5c2e88 100644 (file)
@@ -50,7 +50,6 @@
 #include <inttypes.h>
 #include <fcntl.h>
 #include <locale.h>
-#include <libiberty.h>
 #include <linux/lustre/lustre_user.h>
 
 #ifdef HAVE_SELINUX
@@ -86,6 +85,21 @@ ssize_t statx(int dfd, const char *filename, int flags,
 }
 #endif /* HAVE_STATX */
 
+#define xstrdup(str) strdup(str)
+static inline
+char *xasprintf(const char *fmt, const char *old_fmt, const char *str)
+{
+       char *tmp = NULL;
+
+       if (asprintf(&tmp, fmt, old_fmt, str) < 0) {
+               fprintf(stderr, "asprintf allocation failed\n");
+               exit(1);
+       }
+
+       return tmp;
+}
+
+
 /* coreutils/lib/intprops.h */
 #define _GL_SIGNED_TYPE_OR_EXPR(t) TYPE_SIGNED(__typeof__(t))
 
@@ -159,9 +173,10 @@ static char const printf_flags[] = "'-+ #0I";
 static char const fmt_terse_fs[] = "%n %i %l %t %s %S %b %f %a %c %d\n";
 static char const fmt_terse_regular[] = "%n %s %b %f %u %g %D %i %h %t %T"
                                        " %X %Y %Z %W %o\n";
+#ifdef HAVE_SELINUX
 static char const fmt_terse_selinux[] = "%n %s %b %f %u %g %D %i %h %t %T"
                                        " %X %Y %Z %W %o %C\n";
-
+#endif
 static char *format;
 
 /* Whether to follow symbolic links;  True for --dereference (-L).  */
@@ -925,8 +940,10 @@ static int out_file_context(char *pformat, size_t prefix_len,
 
        strcpy(pformat + prefix_len, "s");
        printf(pformat, (scontext ? scontext : "?"));
+#ifdef HAVE_SELINUX
        if (scontext)
                freecon(scontext);
+#endif
        return rc;
 }
 
@@ -1291,6 +1308,7 @@ static char *default_format(bool fs, bool terse, bool device)
 ");
                        free(temp);
 
+#ifdef HAVE_SELINUX
                        if (is_selinux_enabled() > 0) {
                                temp = format;
                                /* TRANSLATORS: This string uses format
@@ -1301,7 +1319,7 @@ static char *default_format(bool fs, bool terse, bool device)
                                                   "Context: %C\n");
                                free(temp);
                        }
-
+#endif
                        temp = format;
                        /* TRANSLATORS: This string uses format specifiers from
                         * 'stat --help' without --file-system, and NOT from