#include <inttypes.h>
#include <fcntl.h>
#include <locale.h>
-#include <libiberty.h>
#include <linux/lustre/lustre_user.h>
#ifdef HAVE_SELINUX
}
#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))
/* Formats for the --terse option. */
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";
-static char const fmt_terse_selinux[] = "%n %s %b %f %u %g %D %i %h %t %T"
- " %X %Y %Z %W %o %C\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). */
return ch;
}
-void usage(char *prog)
+static void usage(char *prog)
{
printf("Usage: %s [options] <FILE>...\n", prog);
printf("Display file status via statx() syscall.\n"
"\t%%n file name\n"
"\t%%N quoted file name with dereference if symbolic link\n"
"\t%%o optimal I/O transfer size hint\n"
- "\t%%q Mask to show what's supported in stx_attributes\n"
+ "\t%%p Mask to show what's supported in stx_attributes\n"
"\t%%r Flags conveying information about the file: "
"stx_attributes\n"
"\t%%s total size, in bytes\n"
static void strmode(mode_t mode, char *str)
{
str[0] = ftypelet(mode);
- str[1] = mode & S_IRUSR ? 'r' : '-';
- str[2] = mode & S_IWUSR ? 'w' : '-';
+ str[1] = mode & 0400 ? 'r' : '-';
+ str[2] = mode & 0200 ? 'w' : '-';
str[3] = (mode & S_ISUID
- ? (mode & S_IXUSR ? 's' : 'S')
- : (mode & S_IXUSR ? 'x' : '-'));
- str[4] = mode & S_IRGRP ? 'r' : '-';
- str[5] = mode & S_IWGRP ? 'w' : '-';
+ ? (mode & 0100 ? 's' : 'S')
+ : (mode & 0100 ? 'x' : '-'));
+ str[4] = mode & 0040 ? 'r' : '-';
+ str[5] = mode & 0020 ? 'w' : '-';
str[6] = (mode & S_ISGID
- ? (mode & S_IXGRP ? 's' : 'S')
- : (mode & S_IXGRP ? 'x' : '-'));
- str[7] = mode & S_IROTH ? 'r' : '-';
- str[8] = mode & S_IWOTH ? 'w' : '-';
+ ? (mode & 0010 ? 's' : 'S')
+ : (mode & 0010 ? 'x' : '-'));
+ str[7] = mode & 0004 ? 'r' : '-';
+ str[8] = mode & 0002 ? 'w' : '-';
str[9] = (mode & S_ISVTX
- ? (mode & S_IXOTH ? 't' : 'T')
- : (mode & S_IXOTH ? 'x' : '-'));
+ ? (mode & 0001 ? 't' : 'T')
+ : (mode & 0001 ? 'x' : '-'));
str[10] = ' ';
str[11] = '\0';
}
static void filemodestring(struct statx const *stxp, char *str)
{
strmode(stxp->stx_mode, str);
-
-/*
- if (S_TYPEISSEM(statp))
- str[0] = 'F';
- else if (IS_MIGRATED_FILE (statp))
- str[0] = 'M';
- else if (S_TYPEISMQ (statp))
- str[0] = 'Q';
- else if (S_TYPEISSHM (statp))
- str[0] = 'S';
- else if (S_TYPEISTMO (statp))
- str[0] = 'T';
- */
}
/* gnulib/lib/file-type.c */
if (w > 1) {
char *dst = pformat;
char const *src = dst;
+
for (; src < p; src++) {
if (*src == '-')
frac_left_adjust = true;
strcpy(pformat + prefix_len, "s");
printf(pformat, (scontext ? scontext : "?"));
+#ifdef HAVE_SELINUX
if (scontext)
freecon(scontext);
+#endif
return rc;
}
/* Map a TS with negative TS.tv_nsec to {0,0}. */
static inline struct timespec neg_to_zero(struct timespec ts)
{
- if (ts.tv_nsec >= 0) {
+ if (ts.tv_nsec >= 0)
return ts;
- } else {
- struct timespec z = {0, 0};
- return z;
- }
+ struct timespec z = {0, 0};
+
+ return z;
}
/* All the mode bits that can be affected by chmod. */
#define CHMOD_MODE_BITS \
- (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
+ (S_ISUID | S_ISGID | S_ISVTX | 0700 | 0070 | 0007)
/* Print statx info. Return zero upon success, nonzero upon failure. */
static int print_statx(char *pformat, size_t prefix_len, unsigned int m,
");
free(temp);
+#ifdef HAVE_SELINUX
if (is_selinux_enabled() > 0) {
temp = format;
/* TRANSLATORS: This string uses format
"Context: %C\n");
free(temp);
}
-
+#endif
temp = format;
/* TRANSLATORS: This string uses format specifiers from
* 'stat --help' without --file-system, and NOT from
DIR *dir;
struct dirent *ent;
char fullname[PATH_MAX];
+ size_t size = sizeof(fullname);
+ int namelen;
int rc = 0;
dir = opendir(dirname);
rc = -ENAMETOOLONG;
continue;
}
- snprintf(fullname, PATH_MAX, "%s/%s",
- dirname, ent->d_name);
+ namelen = snprintf(fullname, size, "%s/%s",
+ dirname, ent->d_name);
+ if (namelen >= size)
+ fullname[size - 1] = '\0';
+
ret = do_statx(fullname, request_mask, flags);
if (!ret)
putchar('\n');