/* Portions Copyright 2006 Stephen P. Potter */
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* ls
*
* 4.2bsd version for symbolic links, variable length
* directory entries, block size in the inode, etc.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stddef.h>
#include <dirent.h>
#include <ctype.h>
#include <time.h>
#include <limits.h>
#include <locale.h>
#include <errno.h>
struct afile {
};
static struct subdirs {
char *sd_name;
} *subdirs;
static int usetabs;
static int twidth;
static int fcmp(const void *, const void *);
static char *cat(char *, char *);
static char *savestr(char *);
static void formatd(char *, int);
int
{
int i;
if (getuid() == 0)
Aflg++;
now += 60;
twidth = 80;
if (isatty(1)) {
usetabs = 1;
} else
usetabs = 1;
(*argv)++;
while (**argv) {
switch (*(*argv)++) {
case 'C':
Cflg = 1; break;
case 'q':
qflg = 1; break;
case '1':
Cflg = 0; break;
case 'a':
aflg++; break;
case 'A':
Aflg++; break;
case 'c':
cflg++; break;
case 's':
sflg++; break;
case 'd':
dflg++; break;
case 'g':
gflg++; break;
case 'l':
lflg++; break;
case 'r':
rflg = -1; break;
case 't':
tflg++; break;
case 'u':
uflg++; break;
case 'i':
iflg++; break;
case 'f':
fflg++; break;
case 'L':
Lflg++; break;
case 'F':
Fflg++; break;
case 'R':
Rflg++; break;
}
}
}
if (fflg) {
}
if (lflg)
Cflg = 0;
if (argc == 0) {
argc++;
}
if (fp == 0) {
exit(1);
}
for (i = 0; i < argc; i++) {
fp++;
}
argv++;
}
if (dflg) {
exit(0);
}
if (fflg)
else {
continue;
}
(void) printf("\n");
for (;;) {
while (subdirs) {
struct subdirs *t;
(void) printf("\n");
free(t);
}
break;
(void) printf("\n");
}
}
return (0);
}
static void
{
if (dfp0 == 0)
return;
if (fflg == 0)
if (title)
if (Rflg)
continue;
}
}
}
static off_t
{
/*
* This code (opendir, readdir, and the "for" loop) is arranged in
* this strange manner to handle the case where UNIX lets root open
* any directory for reading, but NFS does not let root read the
* openned directory.
*/
return (0);
}
errno = 0;
/* root reading across NFS can get to this error case */
return (0);
}
continue;
continue;
continue;
fp++;
if (*pfp0 == 0) {
exit(1);
}
nent *= 2;
}
}
}
static struct afile *
{
int cc;
int aclcnt;
"%s not found\n", file);
else {
}
return (0);
}
}
case S_IFDIR:
case S_IFDOOR:
case S_IFBLK:
case S_IFCHR:
case S_IFSOCK:
case S_IFIFO:
case S_IFLNK:
if (lflg) {
if (cc >= 0) {
/*
* here we follow the symbolic
* link to generate the proper
* Fflg marker for the object,
*/
case S_IFDIR:
break;
case S_IFDOOR:
break;
case S_IFIFO:
break;
case S_IFSOCK:
break;
default:
& 0111)
break;
}
}
break;
}
/*
* this is a hack from UCB to avoid having
* ls /bin behave differently from ls /bin/
* when /bin is a symbolic link. We hack the
* hack to have that happen, but only for
* explicit arguments, by inspecting pnb.
*/
break;
}
break;
}
/* ACL: check acl entries count */
/* this file has a non-trivial acl */
/*
* For files with non-trivial acls, the
* effective group permissions are the
* intersection of the GROUP_OBJ value and
* the CLASS_OBJ (acl mask) value. Determine
* both the GROUP_OBJ and CLASS_OBJ for this
* file and insert the logical AND of those
* two values in the group permissions field
* of the lflags value for this file.
*/
perror("ls");
exit(2);
}
return (0);
}
/*
* Until found in acl list, assume maximum
* permissions for both group and mask. (Just
* in case the acl lacks either value for
* some reason.)
*/
groupperm = 07;
mask = 07;
grouppermfound = 0;
maskfound = 0;
grouppermfound = 1;
continue;
}
maskfound = 1;
}
if (grouppermfound && maskfound)
break;
}
/* reset all the group bits */
/*
* Now set them to the logical AND of the
* GROUP_OBJ permissions and the acl mask.
*/
} else
if (uflg)
else if (cflg)
else
if (pnb)
}
return (fp);
}
static void
{
char *cp;
return;
columns = 1;
else {
}
if (usetabs)
else
width += 2;
if (columns == 0)
columns = 1;
}
for (i = 0; i < lines; i++) {
for (j = 0; j < columns; j++) {
(void) printf("\n");
break;
}
while (w < width)
if (usetabs) {
w = (w + 8) &~ 7;
(void) putchar('\t');
} else {
w++;
(void) putchar(' ');
}
}
}
}
static int
{
return (1);
} else {
return (-1);
}
}
if (tflg) {
return (0);
return (rflg);
return (-rflg);
}
}
static char *
{
exit(1);
}
return (dfile);
}
return (dfile);
}
static char *
{
exit(1);
}
return (cp);
}
static char *fmtmode(char *, int);
static char *
{
*dp++ = '?';
else
/* avoid both "->" and trailing marks */
*dp++ = '/';
*dp++ = '>';
*dp++ = '|';
*dp++ = '@';
*dp++ = '=';
*dp++ = '*';
}
*dp++ = '?';
else
}
*dp++ = 0;
return (fmtres);
}
static char *
{
return (inumbuf);
}
static char *
{
return (sizebuf);
}
static char *
{
/* type mode uname gname fsize ftime */
/* get uname */
{
}
/* get gname */
if (gflg) {
}
/* get fsize */
else if (p->ftype == 's')
else
"%lld", p->fsize);
/* get ftime */
{
else
}
/* splat */
return (lstuffbuf);
}
static int m1[] =
static int m2[] =
static int m3[] =
static int m4[] =
static int m5[] =
static int m6[] =
static int m7[] =
static int m8[] =
static int m9[] =
static char *
{
int **mp;
register int n = *pairp++;
while (n-- > 0) {
pairp++;
break;
} else
pairp += 2;
}
}
return (lp);
}
/* rest should be done with nameserver or database */
#include <pwd.h>
#include <grp.h>
#include <utmpx.h>
static struct cachenode *
{
while (c != NULL) {
/* found it */
return (c);
c = c->lesschild;
} else {
c = c->grtrchild;
}
}
/* not in the cache, make a new entry for it */
return (c);
}
static char *
{
struct cachenode *c;
if (c->initted == 0) {
} else {
}
c->initted = 1;
}
return (&c->name[0]);
}
static char *
{
struct cachenode *c;
if (c->initted == 0) {
} else {
}
c->initted = 1;
}
return (&c->name[0]);
}