-.\" $OpenBSD: file.1,v 1.41 2015/04/27 11:12:49 jmc Exp $
+.\" $OpenBSD: file.1,v 1.42 2015/05/30 06:25:35 nicm Exp $
.\" $FreeBSD: src/usr.bin/file/file.1,v 1.16 2000/03/01 12:19:39 sheldonh Exp $
.\"
.\" Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org>
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd $Mdocdate: April 27 2015 $
+.Dd $Mdocdate: May 30 2015 $
.Dt FILE 1
.Os
.Sh NAME
.Em data
meaning anything else.
.Pp
+If
+.Ar file
+is a single dash
+.Pq Sq - ,
+.Nm
+reads from the standard input.
+.Pp
The options are as follows:
.Bl -tag -width indent
.It Fl b
-/* $OpenBSD: file.c,v 1.44 2015/05/29 15:58:34 nicm Exp $ */
+/* $OpenBSD: file.c,v 1.45 2015/05/30 06:25:35 nicm Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org>
memset(&msg, 0, sizeof msg);
msg.idx = idx;
- if (lstat(argv[idx], &msg.sb) == -1) {
+ if (strcmp(argv[idx], "-") == 0) {
+ if (fstat(STDIN_FILENO, &msg.sb) == -1) {
+ fd = -1;
+ msg.error = errno;
+ } else
+ fd = STDIN_FILENO;
+ } else if (lstat(argv[idx], &msg.sb) == -1) {
fd = -1;
msg.error = errno;
} else {
strerror(inf->msg->error));
return (1);
}
- if (sflag) {
+ if (sflag || strcmp(inf->path, "-") == 0) {
switch (inf->msg->sb.st_mode & S_IFMT) {
+ case S_IFIFO:
+ if (strcmp(inf->path, "-") != 0)
+ break;
case S_IFBLK:
case S_IFCHR:
case S_IFREG:
if (bflag)
printf("%s\n", inf->result);
else {
- xasprintf(&label, "%s:", inf->path);
+ if (strcmp(inf->path, "-") == 0)
+ xasprintf(&label, "/dev/stdin:");
+ else
+ xasprintf(&label, "%s:", inf->path);
printf("%-*s %s\n", (int)width, label, inf->result);
free(label);
}