• [^] # Re: Et sans getgr[ug]id ?

    Posté par . En réponse au message Un probleme sur mon code. Évalué à 1.

    Voila ou en est mon code


    #include <stdio.h>
    #include <unistd.h>
    #include <dirent.h>
    #include <stdio.h>
    #include <unistd.h>
    #include <errno.h>
    #include <pwd.h>
    #include <grp.h>
    #include <time.h>
    #include <string.h>
    #include <sys/stat.h>
    #include <sys/types.h>

    void aff_info(char *file, struct stat buf)
    {
    struct group *g;
    struct passwd *pwd;

    if (stat(file, &buf) != 0)
    {
    printf("%d", stat(file, &buf));
    printf ("erreur %s\n", strerror(errno));
    exit(-1);
    }
    g = getgrgid(buf.st_gid);
    pwd = getpwuid(buf.st_uid);
    printf("~~ Variables de stat sur %s ~~ \n\n", file);
    printf("-Peripherique: %d\n", buf.st_dev);
    printf("-Numero I-Noeud: %d\n", buf.st_ino);
    printf("-Modes: %o\n", buf.st_mode);
    printf("-Nb Liens materiels: %d\n", buf.st_nlink);
    printf("-UID: %s\n", pwd->pw_name);
    printf("-GID: %s\n\n", g->gr_name);
    return ;
    }

    void read_folder(DIR *dir)
    {
    struct dirent *d;
    struct stat buf;

    while (d = readdir(dir))
    {
    aff_info(d->d_name, buf);
    }
    }

    int main(int argc, char **argv)
    {
    DIR *dir;

    if (argc != 2)
    {
    printf("Comment on m'utilise ?\n%s dossier", argv[0]);
    exit(1);
    }
    if ((dir = opendir(argv[1])) == NULL)
    {
    printf("Probleme avec Opendir.");
    exit(1);
    }
    read_folder(dir);
    closedir(dir);
    }