int main(int argc, char *argv[]) { DIR *d; struct dirent *de; struct stat s; chdir("/proc"); archivefile("meminfo", 1); archivefile("version", 1); d = opendir("."); while ((de = readdir(d))) if (de->d_name[0] >= '0' && de->d_name[0] <= '9') { stat (de->d_name, &s); writeheader(1, de->d_name, 0555, s.st_uid, s.st_gid, 0, s.st_mtime, 5); archivejoin(de->d_name, "smaps", 1); archivejoin(de->d_name, "cmdline", 1); archivejoin(de->d_name, "stat", 1); } return 0; }
static void archivejoin(const char *sub, const char *name) { char path[sizeof(long long)*3 + sizeof("/cmdline")]; sprintf(path, "%s/%s", sub, name); archivefile(path); }
int archivejoin(const char *sub, const char *name, int destfd) { char path[256]; sprintf(path, "%s/%s", sub, name); return archivefile(path, destfd); }