¿Por qué no me funciona el stat?
Código (c) [Seleccionar]
#include<unistd.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdio.h>
#include<errno.h>
#include<sys/types.h>
#include<dirent.h>
#include<string.h>
int main(int argc, char *argv[])
{
DIR *dir;
struct dirent *ent;
char **ptr;
long octal;
if( strlen(argv[2]) != 4){
printf("\nError al introducir el numero de digitos del parametro 2\n");
exit(-1);
}
if( (dir=opendir(argv[1]))==NULL){
printf("\nError en el primer open\n");
exit(-1);
}
octal = strtol(argv[2], ptr, 8);
struct stat *atributos;
int fd;
while ((ent = readdir(dir)) != NULL){
if( (strcmp(ent->d_name, ".")!=0) && (strcmp(ent->d_name, "..")!=0) ){
if ( (fd = open(ent->d_name,O_CREAT|O_TRUNC|O_WRONLY,S_IRGRP|S_IWGRP|S_IXGRP))<0){
printf("\nError en el segundo open\n");
exit(-1);
}
printf("%s", ent->d_name);
printf("%s\n", " : ");
if ( (stat(ent->d_name, atributos)) <0){
printf("\nError en stat\n");
exit(-1);
}
chmod(ent->d_name, octal);
close(fd);
}
}