3
我剛剛開始閱讀Unix環境下的高級編程。第一個例子是針對ls的實現,代碼如下。我不明白的是DIR定義的地方。我看了apue.h(不在那裏)和dirent.h(不在那裏)。任何人都可以告訴我它在哪裏定義?DIR定義在哪裏?
#include "apue.h"
#include <dirent.h>
#include <stdlib.h>
int
main(int argc, char *argv[])
{
DIR *dp;
struct dirent *dirp;
if (argc != 2)
err_quit("usage: ls directory_name");
if ((dp = opendir(argv[1])) == NULL)
err_sys("can't open %s", argv[1]);
while ((dirp = readdir(dp)) != NULL)
printf("%s\n", dirp->d_name);
closedir(dp);
exit(0);
你在哪個平臺上?在linux上,它在dirent.h中:'typedef struct __dirstream DIR'。你可以運行'grep DIR /usr/include/*.h /usr/include/*/*.h | grep typedef'來自己找出。 – isedev
感謝您的回覆。它位於我係統上的apr_portable.h – user3233706
@isedev:更簡單:'grep -r'typedef。* DIR'/ usr/include',或者'find/usr/include -type f -name'* .h'| xargs grep'typedef。* DIR'' –