2 * Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
38 #include <sys/sysmacros.h>
43 timesince(long timesec)
45 long d_since; /* days */
46 long h_since; /* hours */
47 long m_since; /* minutes */
48 long s_since; /* seconds */
50 s_since = timebuf - timesec;
51 d_since = s_since / 86400l ;
52 s_since -= d_since * 86400l ;
53 h_since = s_since / 3600l ;
54 s_since -= h_since * 3600l ;
55 m_since = s_since / 60l ;
56 s_since -= m_since * 60l ;
58 printf("(%05ld.%02ld:%02ld:%02ld)\n",
59 d_since, h_since, m_since, s_since);
63 main(int argc, char **argv)
71 for (i = 1; i < argc; i++) {
73 if( lstat64(argv[i], &sbuf) < 0) {
78 printf(" File: \"%s\"\n", argv[i]);
79 printf(" Size: %-10llu", (unsigned long long)sbuf.st_size);
81 strcpy(mode,"----------");
82 if (sbuf.st_mode & (S_IEXEC>>6))
84 if (sbuf.st_mode & (S_IWRITE>>6))
86 if (sbuf.st_mode & (S_IREAD>>6))
88 if (sbuf.st_mode & (S_IEXEC>>3))
90 if (sbuf.st_mode & (S_IWRITE>>3))
92 if (sbuf.st_mode & (S_IREAD>>3))
94 if (sbuf.st_mode & S_IEXEC)
96 if (sbuf.st_mode & S_IWRITE)
98 if (sbuf.st_mode & S_IREAD)
100 if (sbuf.st_mode & S_ISVTX)
102 if (sbuf.st_mode & S_ISGID)
104 if (sbuf.st_mode & S_ISUID)
107 printf(" Filetype: ");
108 switch (sbuf.st_mode & S_IFMT) {
118 puts("Character Device");
122 puts("Block Device");
126 puts("Regular File");
130 puts("Symbolic Link");
142 printf(" Mode: (%04o/%s)", (unsigned int)(sbuf.st_mode & 07777), mode);
143 printf(" Uid: (%d)", (int)sbuf.st_uid);
144 printf(" Gid: (%d)\n", (int)sbuf.st_gid);
145 printf("Device: %2d,%-2d", major(sbuf.st_dev),
147 printf(" Inode: %-9llu", (unsigned long long)sbuf.st_ino);
148 printf(" Links: %-5ld", (long)sbuf.st_nlink);
150 if ( ((sbuf.st_mode & S_IFMT) == S_IFCHR)
151 || ((sbuf.st_mode & S_IFMT) == S_IFBLK) )
152 printf(" Device type: %2d,%-2d\n",
153 major(sbuf.st_rdev), minor(sbuf.st_rdev));
157 printf("Access: %.24s",ctime(&sbuf.st_atime));
158 timesince(sbuf.st_atime);
159 printf("Modify: %.24s",ctime(&sbuf.st_mtime));
160 timesince(sbuf.st_mtime);
161 printf("Change: %.24s",ctime(&sbuf.st_ctime));
162 timesince(sbuf.st_ctime);
168 fprintf(stderr, "Usage: lstat64 filename...\n");