* finfo - print file info
*/
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include <sys/types.h>
#include "posixstat.h"
#include <stdio.h>
#include <grp.h>
#include <errno.h>
+#include "bashansi.h"
#include "shell.h"
#include "builtins.h"
#include "common.h"
extern int errno;
#endif
-extern char *strrchr();
extern char **make_builtin_argv ();
static int printst();
{
static struct stat st;
int fd, r;
- long lfd;
+ intmax_t lfd;
if (strncmp(f, "/dev/fd/", 8) == 0) {
- if (legal_number(f + 8, &lfd) == 0) {
+ if ((legal_number(f + 8, &lfd) == 0) || (int)lfd != lfd) {
builtin_error("%s: invalid fd", f + 8);
return ((struct stat *)0);
}
fd = lfd;
r = fstat(fd, &st);
} else
+#ifdef HAVE_LSTAT
+ r = lstat(f, &st);
+#else
r = stat(f, &st);
+#endif
if (r < 0) {
builtin_error("%s: cannot stat: %s", f, strerror(errno));
return ((struct stat *)0);
obits[i++] = 'x';
obits[i] = '\0';
+ if (m & S_ISUID)
+ ubits[2] = (m & S_IXUSR) ? 's' : 'S';
+ if (m & S_ISGID)
+ gbits[2] = (m & S_IXGRP) ? 's' : 'S';
+ if (m & S_ISVTX)
+ obits[2] = (m & S_IXOTH) ? 't' : 'T';
+
printf ("u=%s,g=%s,o=%s", ubits, gbits, obits);
}
printf("S_IFLNK ");
if (S_ISSOCK(mode))
printf("S_IFSOCK ");
+#ifdef S_ISWHT
+ if (S_ISWHT(mode))
+ printf("S_ISWHT ");
+#endif
perms(getperm(mode));
printf("\n");
}
}
#ifndef NOBUILTIN
+int
finfo_builtin(list)
WORD_LIST *list;
{