add ls; simpler pwd

This commit is contained in:
Connor Lane Smith
2011-05-26 04:01:20 +01:00
parent 273f150c84
commit 6ef3d9174b
9 changed files with 268 additions and 24 deletions

20
util/agetcwd.c Normal file
View File

@@ -0,0 +1,20 @@
/* See LICENSE file for copyright and license details. */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "../util.h"
char *
agetcwd(void)
{
char *buf;
size_t size;
if((size = pathconf(".", _PC_PATH_MAX)) < 0)
size = BUFSIZ;
if(!(buf = malloc(size)))
eprintf("malloc:");
if(!getcwd(buf, size))
eprintf("getcwd:");
return buf;
}

View File

@@ -11,7 +11,6 @@ void
recurse(const char *path, void (*fn)(const char *))
{
char *buf;
long size;
struct dirent *d;
DIR *dp;
@@ -21,12 +20,7 @@ recurse(const char *path, void (*fn)(const char *))
else
eprintf("opendir %s:", path);
}
if((size = pathconf(".", _PC_PATH_MAX)) < 0)
size = BUFSIZ;
if(!(buf = malloc(size)))
eprintf("malloc:");
if(!getcwd(buf, size))
eprintf("getcwd:");
buf = agetcwd();
if(chdir(path) != 0)
eprintf("chdir %s:", path);
while((d = readdir(dp)))