예제 #1
0
파일: ft_infos.c 프로젝트: hikkary/ft_mls
t_file	*ft_putinfo(t_file *file, char *filename, char *dirname, int isln)
{
	ssize_t		i;
	t_stat	filestats;
	char	*path;
	
	path = ft_strjoin(dirname, "/");
	path = ft_strjoin(path, filename);
	if ((lstat(path, &filestats)) == -1)
		lstat(filename, &filestats);
	file->type = ft_gettype(filestats);
	file->rights = ft_getrights(filestats);
	file->links = (int)(filestats.st_nlink);
	file->uname = (getpwuid(filestats.st_uid))->pw_name;
	file->gname = (getgrgid(filestats.st_gid))->gr_name;
	if (file->type != 'b' && file->type != 'c')
		file->size = filestats.st_size;
	file->lnpath = malloc(sizeof(char ) * ft_strlen(filename) + 1);
	file->laccess = filestats.st_atimespec;
	file->blocks = filestats.st_blocks;
	file->ldatamod = filestats.st_mtimespec;
	file->lstatch = filestats.st_ctimespec;
	file->birthtime = filestats.st_birthtimespec;
	file->dname = ft_strdup(filename);
	//printf("%c\n", file->type);
	if (file->type == 'l')
	{
		if ((i = readlink(filename, file->lnpath, file->size)) != -1)
			file->lnpath[i] = '\0';
	}
		//else
		//	return ;
	if (file->type == 'c' || file->type == 'b')
	{
		file->major = (int)major(filestats.st_rdev);
		file->minor = (int)minor(filestats.st_rdev);
	}
	return(file);
}
예제 #2
0
char		*ft_getmode(int mode)
{
	char *str;

	str = (char *)malloc(sizeof(char) * 10 + 1);
	if (!str)
		return (NULL);
	str[0] = ft_gettype(mode);
	str[1] = 00400 & mode ? 'r' : '-';
	str[2] = 00200 & mode ? 'w' : '-';
	str[3] = 00100 & mode ? 'x' : '-';
	str[3] = ft_getmode_(str[3], mode, 1);
	str[4] = 00040 & mode ? 'r' : '-';
	str[5] = 00020 & mode ? 'w' : '-';
	str[6] = 00010 & mode ? 'x' : '-';
	str[6] = ft_getmode_(str[6], mode, 2);
	str[7] = 00004 & mode ? 'r' : '-';
	str[8] = 00002 & mode ? 'w' : '-';
	str[9] = 00001 & mode ? 'x' : '-';
	str[9] = ft_getmode_(str[9], mode, 3);
	str[10] = 0;
	return (str);
}