Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Тестовые примеры / ch12 / scan / scan_1
.c#include <rpc/rpc.h>
#include <dirent.h>
#include <string.h>
#include <malloc.h>
#include <sys/stat.h>
#include "scan.h"
extern int errno;
res* scandir_1(argPtr* darg)
{
DIR *dirp;
struct dirent *d;
infolist nl, *nlp;
struct stat statv;
static res res;
if (!(dirp = opendir((*darg)->dir_name))) {
res.errno = errno; return &res;
}
xdr_free(xdr_res, (void*)&res);
nlp = &res.res_u.list;
while (d=readdir(dirp)) {
nl = *nlp = (infolist)malloc(sizeof(struct dirinfo));
nl->name = strdup(d->d_name);
nlp = &nl->next;
if ((*darg)->lflag) {
char pathnm[256];
sprintf(pathnm,"%s/%s",(*darg)->dir_name,d->d_name);
if (!stat(pathnm,&statv)) {
nl->uid = statv.st_uid;
nl->modtime = statv.st_mtime;
}
}
}
*nlp = NULL;
res.errno = 0;
closedir(dirp);
return &res;
}