Fire Fox II
18-04-2004, 17:13
Salve raga :)
innanzitutto mi scuso x la banalità della domanda :D ma essendomi perso alcune lezioni all'uni, non capisco il significato di una funzione... (la struct)
X esempio, in questo prog
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
int main()
{
char c, cwd[100];
int fd;
struct stat buf;
struct dirent *drn;
DIR *dp;
getcwd(cwd,sizeof(cwd));
if((dp=opendir(cwd))==NULL)
printf("opendir error\n");
while((drn=readdir(dp))!=NULL)
{
printf("Il nome del file e' %s\n",drn->d_name);
if(lstat(drn->d_name,&buf) <0)
printf("Errore lstat su %s\n",drn->d_name);
if(S_ISLNK(buf.st_mode))
{
printf("Trovato il link %s\n",drn->d_name);
fd=open(drn->d_name,O_RDONLY);
while ( read(fd, &c, 1) > 0)
write(STDOUT_FILENO, &c, 1);
}
}
closedir(dp);
exit(0);
}
potreste dirmi a cosa servono le stringhe
struct stat buf;
struct dirent *drn;
Grazie mille x l'aiuto ;)
innanzitutto mi scuso x la banalità della domanda :D ma essendomi perso alcune lezioni all'uni, non capisco il significato di una funzione... (la struct)
X esempio, in questo prog
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
int main()
{
char c, cwd[100];
int fd;
struct stat buf;
struct dirent *drn;
DIR *dp;
getcwd(cwd,sizeof(cwd));
if((dp=opendir(cwd))==NULL)
printf("opendir error\n");
while((drn=readdir(dp))!=NULL)
{
printf("Il nome del file e' %s\n",drn->d_name);
if(lstat(drn->d_name,&buf) <0)
printf("Errore lstat su %s\n",drn->d_name);
if(S_ISLNK(buf.st_mode))
{
printf("Trovato il link %s\n",drn->d_name);
fd=open(drn->d_name,O_RDONLY);
while ( read(fd, &c, 1) > 0)
write(STDOUT_FILENO, &c, 1);
}
}
closedir(dp);
exit(0);
}
potreste dirmi a cosa servono le stringhe
struct stat buf;
struct dirent *drn;
Grazie mille x l'aiuto ;)