は基本的に、これはディレクトリストリームを開き、シンボリックリンクを探し、コードのシンプルな作品でなければなりません。シンボリックリンクが見つかるたびに、それが印刷されます( "シンボリックリンクが見つかりました")。 しかし、lstat(dirp->d_name,&buf
コールでは常に値<が返されますが、その理由はわかりません。 私は、私は後で私のコードでclosedir()
を呼び出す必要があります知っている2つのシンボリックリンク、ファイルフォルダを開くと、フォルダ内のターミナルウィンドウを開き、 ln -s ciao.txt link1
と ln -s ciao2.txt link2
を実行しているを作成し、これを気にしないでください。LSTATは、<0
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
void main (int argc, char* argv[])
{
char buffer[100],dir[100];
struct stat buf;
int x;
DIR *dp;
struct dirent *dirp;
if((dp=opendir(argv[1]))==NULL)
{
printf("\nError opening directory stream, now exiting...\n");
exit(-1);
}
while((dirp=readdir(dp))!=NULL)
{
lstat(dirp->d_name,&buf);
if(S_ISLNK(buf.st_mode))
printf("\n%s Is a symbolic link\n",dirp->d_name);
else
printf("\n%s Is not a symbolic link\n",dirp->d_name);
}
}
何か助けていただければ幸いです。ありがとう。
私はLSTATコールをチェックし、それが0 <戻っていると私は理由を知りません。 –