File:  [Research Unix] / researchv10no / cmd / asd++ / dir.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:21:34 2018 UTC (8 years, 1 month ago) by root
Branches: belllabs, MAIN
CVS tags: researchv10, HEAD
researchv10 Norman

#include "decl.h"
#include <dir.h>

int
isdir (Path& p)
{
	struct stat sb;

	if (stat (p, &sb) < 0)
		return 0;
	return (sb.st_mode & S_IFMT) == S_IFDIR;
}

static char*
charconv (String& s)
{
	char *p = new char[s.length() + 1];
	s.dump (p);
	return p;
}

Path_list
dircontents (Path& p)
{
	Path_list r;
	char *cp = charconv (String(p));
	DIR *df = opendir (cp);

	if (df) {
		direct *dp;
		while (dp = readdir (df)) {
			Path ds = dp->d_name;
			if (ds != "." && ds != "..") {
				Path_list_iterator i (r);
				Path x;

				while (i.peekX (x) && x < ds)
					i.next();

				i.insert (ds);
			}
		}

		closedir (df);
	}

	delete cp;

	return r;
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.