[BACK]Return to tls.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / distrib / utils / tls

File: [cvs.NetBSD.org] / src / distrib / utils / tls / tls.c (download)

Revision 1.1.1.1 (vendor branch), Sun Oct 8 23:08:47 1995 UTC (28 years, 5 months ago) by gwr
Branch: GWR
CVS Tags: wrstuden-devbsize-base, wrstuden-devbsize-19991221, wrstuden-devbsize, netbsd-3-base, netbsd-3-1-RELEASE, netbsd-3-1-RC4, netbsd-3-1-RC3, netbsd-3-1-RC2, netbsd-3-1-RC1, netbsd-3-1-1-RELEASE, netbsd-3-1, netbsd-3-0-RELEASE, netbsd-3-0-RC6, netbsd-3-0-RC5, netbsd-3-0-RC4, netbsd-3-0-RC3, netbsd-3-0-RC2, netbsd-3-0-RC1, netbsd-3-0-3-RELEASE, netbsd-3-0-2-RELEASE, netbsd-3-0-1-RELEASE, netbsd-3-0, netbsd-3, netbsd-2-base, netbsd-2-1-RELEASE, netbsd-2-1-RC6, netbsd-2-1-RC5, netbsd-2-1-RC4, netbsd-2-1-RC3, netbsd-2-1-RC2, netbsd-2-1-RC1, netbsd-2-1, netbsd-2-0-base, netbsd-2-0-RELEASE, netbsd-2-0-RC5, netbsd-2-0-RC4, netbsd-2-0-RC3, netbsd-2-0-RC2, netbsd-2-0-RC1, netbsd-2-0-3-RELEASE, netbsd-2-0-2-RELEASE, netbsd-2-0-1-RELEASE, netbsd-2-0, netbsd-2, netbsd-1-6-base, netbsd-1-6-RELEASE, netbsd-1-6-RC3, netbsd-1-6-RC2, netbsd-1-6-RC1, netbsd-1-6-PATCH002-RELEASE, netbsd-1-6-PATCH002-RC4, netbsd-1-6-PATCH002-RC3, netbsd-1-6-PATCH002-RC2, netbsd-1-6-PATCH002-RC1, netbsd-1-6-PATCH002, netbsd-1-6-PATCH001-RELEASE, netbsd-1-6-PATCH001-RC3, netbsd-1-6-PATCH001-RC2, netbsd-1-6-PATCH001-RC1, netbsd-1-6-PATCH001, netbsd-1-6, netbsd-1-5-base, netbsd-1-5-RELEASE, netbsd-1-5-PATCH003, netbsd-1-5-PATCH002, netbsd-1-5-PATCH001, netbsd-1-5-BETA2, netbsd-1-5-BETA, netbsd-1-5-ALPHA2, netbsd-1-5, netbsd-1-4-base, netbsd-1-4-RELEASE, netbsd-1-4-PATCH003, netbsd-1-4-PATCH002, netbsd-1-4-PATCH001, netbsd-1-4, netbsd-1-3-base, netbsd-1-3-RELEASE, netbsd-1-3-PATCH003-CANDIDATE2, netbsd-1-3-PATCH003-CANDIDATE1, netbsd-1-3-PATCH003-CANDIDATE0, netbsd-1-3-PATCH003, netbsd-1-3-PATCH002, netbsd-1-3-PATCH001, netbsd-1-3-BETA, netbsd-1-3, netbsd-1-2-base, netbsd-1-2-RELEASE, netbsd-1-2-PATCH001, netbsd-1-2-BETA, netbsd-1-2, netbsd-1-1-base, netbsd-1-1-RELEASE, netbsd-1-1-PATCH001, netbsd-1-1, minoura-xpg4dl-base, minoura-xpg4dl, fvdl_fs64_base, comdex-fall-1999-base, comdex-fall-1999
Changes since 1.1: +0 -0 lines

Add some utilities all ports might use in a ramdisk root.

/*	$NetBSD: tls.c,v 1.1.1.1 1995/10/08 23:08:47 gwr Exp $	*/

/*
 * Copyright (c) 1995 Gordon W. Ross
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 * 4. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by Gordon W. Ross
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <sys/types.h>
#include <sys/stat.h>

#include <dirent.h>
#include <stdio.h>
#include <time.h>

int iflag;

void show_long(char *fname);

main(argc, argv)
	int argc;
	char **argv;
{
	DIR *dfp;
	struct dirent *d;

	/* If given an arg, just cd there first. */
	if (argc > 1) {
		if (chdir(argv[1])) {
			perror(argv[1]);
			exit(1);
		}
	}
	if (argc > 2)
		fprintf(stderr, "extra args ignored\n");

	dfp = opendir(".");
	if (dfp == NULL) {
		perror("opendir");
		return;
	}

	while ((d = readdir(dfp)) != NULL)
		show_long(d->d_name);

	closedir(dfp);
	exit(0);
}

/* XXX - This is system dependent... */
char ifmt_name[16] = {
	'?',	/* 0: nothing */
	'P',	/* 1: fifo (pipe) */
	'C',	/* 2: chr device */
	'?',	/* 3: ? */
	'D',	/* 4: dir */
	'?',	/* 5: ? */
	'B',	/* 6: blk device */
	'?',	/* 7: ? */
	'F',	/* 8: file */
	'?',	/* 9: ? */
	'L',	/* A: link */
	'?',	/* B: ? */
	'S',	/* C: socket */
	'?',	/* D: ? */
	'W',	/* E: whiteout */
	'?' 	/* F: ? */
};

void
show_long(fname)
	char *fname;
{
	struct stat st;
	int ifmt;
	char ifmt_c;
	char *date;

	if (lstat(fname, &st)) {
		perror(fname);
		return;
	}
	ifmt = (st.st_mode >> 12) & 15;
	ifmt_c = ifmt_name[ifmt];

	if (iflag) {
		/* inode number */
		printf("%6d ",  st.st_ino);
	}

	/* fmt/mode */
	printf("%c:",   ifmt_c);
	printf("%04o ", st.st_mode & 07777);

	/* nlinks, uid, gid */
	printf("%2d ",   st.st_nlink);
	printf("%4d ",  st.st_uid);
	printf("%4d ",  st.st_gid);

	/* size or major/minor */
	if ((ifmt_c == 'B') || (ifmt_c == 'C')) {
		printf("%2d, ", major(st.st_rdev));
		printf("%3d ",  minor(st.st_rdev));
	} else {
		printf("%7d ",  (int) st.st_size);
	}

	/* date */
	date = ctime(&st.st_mtime);
	date += 4;	/* skip day-of-week */
	date[12] = '\0';	/* to the minute */
	printf("%s ", date);

	/* name */
	printf("%s", fname);

	if (ifmt_c == 'L') {
		char linkto[256];
		int n;

		n = readlink(fname, linkto, sizeof(linkto)-1);
		if (n < 0) {
			perror(fname);
			return;
		}
		linkto[n] = '\0';
		printf(" -> %s", linkto);
	}
	printf("\n");
}