X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Floadables%2Ffinfo.c;h=b6336296c6af4916ba4c86315cea21233b1b7f46;hb=refs%2Ftags%2Fdevel-base-dist;hp=c0b03652a5056f0e02cc56874f745523c70cb61d;hpb=ccc6cda312fea9f0468ee65b8f368e9653e1380b;p=platform%2Fupstream%2Fbash.git diff --git a/examples/loadables/finfo.c b/examples/loadables/finfo.c index c0b0365..b633629 100644 --- a/examples/loadables/finfo.c +++ b/examples/loadables/finfo.c @@ -2,6 +2,10 @@ * finfo - print file info */ +#ifdef HAVE_CONFIG_H +# include +#endif + #include #include "posixstat.h" #include @@ -9,6 +13,7 @@ #include #include +#include "bashansi.h" #include "shell.h" #include "builtins.h" #include "common.h" @@ -17,7 +22,6 @@ extern int errno; #endif -extern char *strrchr(); extern char **make_builtin_argv (); static int printst(); @@ -127,17 +131,21 @@ char *f; { 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); @@ -196,6 +204,13 @@ int m; 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); } @@ -217,6 +232,10 @@ int mode; 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"); } @@ -333,6 +352,7 @@ int flags; } #ifndef NOBUILTIN +int finfo_builtin(list) WORD_LIST *list; {