apue库环境相关:
apue库的配置过程, 以及对过程中产生错误的处理;
cmake_minimum_required(VERSION 3.0)
project(ApueProject)
set(src main.cc)
set(CMAKE_CXX_STANDARD 17)
link_libraries(apue)
add_executable(main ${src})
#include <iostream>
#include <apue.h>
#include <dirent.h>
using namespace std;
using DIRENT = struct dirent;
int main(int argc, const char * const argv[]) {
DIR *dp;
DIRENT *dirp;
if (argc != 2) {
err_quit("usage: ls directory_name\n");
}
if ((dp = opendir(argv[1])) == nullptr) {
err_sys("can not open %s\n", argv[1]);
}
while ((dirp = readdir(dp)) != nullptr) {
cout << dirp->d_name << endl;
cout << dirp->d_type << endl;
cout << dirp->d_ino << endl;
cout << dirp->d_off << endl;
cout << dirp->d_reclen << endl;
cout << "----------------------------" << endl;
}
closedir(dp);
return 0;
}