determine how to get basic info anot file/dir
This commit is contained in:
parent
5421ebcae5
commit
9cd4eeb8a1
3 changed files with 46 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
||||||
cmake_minimum_required(VERSION 3.6)
|
cmake_minimum_required(VERSION 3.6)
|
||||||
project(ft_ls)
|
project(ft_ls)
|
||||||
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -Wextra")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -Wextra -O0 -g")
|
||||||
|
|
||||||
include_directories(inc libft/includes) # headers
|
include_directories(inc libft/includes) # headers
|
||||||
link_directories(libft) # libraries
|
link_directories(libft) # libraries
|
||||||
|
|
|
@ -13,7 +13,15 @@
|
||||||
#ifndef FT_LS_H
|
#ifndef FT_LS_H
|
||||||
# define FT_LS_H
|
# define FT_LS_H
|
||||||
|
|
||||||
|
# include "libft.h"
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
|
# include <stdio.h>
|
||||||
# include <dirent.h>
|
# include <dirent.h>
|
||||||
|
# include <sys/stat.h>
|
||||||
|
# include <time.h>
|
||||||
|
# include <pwd.h>
|
||||||
|
# include <grp.h>
|
||||||
|
# include <sys/types.h>
|
||||||
|
# include <errno.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
39
src/main.c
39
src/main.c
|
@ -12,7 +12,42 @@
|
||||||
|
|
||||||
#include "ft_ls.h"
|
#include "ft_ls.h"
|
||||||
|
|
||||||
int main(void)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
return (write(1, "aa\n", 3));
|
DIR *dp;
|
||||||
|
struct dirent *ep;
|
||||||
|
struct stat *stat_buf;
|
||||||
|
char *str_tmp;
|
||||||
|
int blocks;
|
||||||
|
|
||||||
|
argc = argc;
|
||||||
|
dp = opendir (argv[1]);
|
||||||
|
blocks = 0;
|
||||||
|
if (dp != NULL)
|
||||||
|
{
|
||||||
|
while ((ep = readdir (dp)))
|
||||||
|
{
|
||||||
|
str_tmp = ft_strjoin("../", ep->d_name);
|
||||||
|
stat_buf = malloc(sizeof(struct stat));
|
||||||
|
stat(str_tmp, stat_buf);
|
||||||
|
printf("%s:\n", str_tmp);
|
||||||
|
printf(" nlinks: %d\n", (int)stat_buf->st_nlink);
|
||||||
|
printf(" st_mode: %d\n", S_ISCHR(stat_buf->st_mode));
|
||||||
|
printf(" MAJOR: %d\n", (int)major(stat_buf->st_rdev));
|
||||||
|
printf(" MINOR: %d\n", (int)minor(stat_buf->st_rdev));
|
||||||
|
printf(" st_uid: %s\n", getpwuid(stat_buf->st_uid)->pw_name);
|
||||||
|
printf(" st_gid: %s\n", getgrgid(stat_buf->st_gid)->gr_name);
|
||||||
|
printf(" st_size: %d\n", (int)stat_buf->st_size);
|
||||||
|
printf(" st_atime: %s", ctime(&stat_buf->st_atim.tv_sec));
|
||||||
|
printf(" st_blocks: %d\n\n", (int)stat_buf->st_blocks);
|
||||||
|
blocks += stat_buf->st_blocks * S_BLKSIZE / 1024;
|
||||||
|
free(stat_buf);
|
||||||
|
free(str_tmp);
|
||||||
|
}
|
||||||
|
(void) closedir (dp);
|
||||||
|
printf(" total blocks: %d\n", blocks);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
printf("%s\n", strerror(errno));
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue