1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include "my_ls.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <stdio.h>
#include <dirent.h>
#include <stdlib.h>
#include <unistd.h>
#include <pwd.h>
#include <grp.h>
int recup_data(char *directory)
{
DIR *dirp;
struct dirent *entry;
list_t *list;
list_add info;
time_t time;
struct stat sb;
struct passwd *user;
list = NULL;
if ((dirp = opendir(directory)) == NULL)
return (-1);
while ((entry = readdir(dirp)) != NULL)
{
stat(entry->d_name, &sb);
user = getpwuid(sb.st_uid);
time = sb.st_mtime;
my_putstr(entry->d_name);//j'ai tésté d'affiché les valeur et elle s'affiche bien.
my_putstr(ctime(&time));
my_putstr(user->pw_name);
my_put_nbr(sb.st_size);
info = add_info(entry->d_name, ctime(&time), user->pw_name, sb.st_size);//Si je ne met pas de info = mon code compile.
add_list(&list, info);
}
}
list_add add_info(char *name, char *time, char *user, int octet)
{
list_add new;
new.name = name;
new.time = time;
new.user = user;
new.octet = octet;
return (new);
}
typedef struct list_s list_t;
typedef struct list_add list_add;
typedef struct param param;
struct list_s
{
char *name;
char *time;
char *user;
int octet;
list_t *next;
};
struct list_add
{
char *name;
char *time;
char *user;
int octet;
};
struct param
{
char letter;
int flag;
}; |