所以我试图使用stat函数获取文件的所有权限。
我的主要问题是,当我发送文件夹作为路径时,stat返回我为-1,但发送“”。给我所有权利,除非找到文件夹。
我添加了两张图片,因为这样可能更容易理解我的问题。 sending two different av.
char *g_permissions(struct stat file_stat, char *permissions)
{
if (!(permissions = malloc(sizeof(char) * 11)))
return (0);
permissions[0] = *((S_ISDIR(file_stat.st_mode)) ? "d" : "-");
permissions[1] = *((file_stat.st_mode & S_IRUSR) ? "r" : "-");
permissions[2] = *((file_stat.st_mode & S_IWUSR) ? "w" : "-");
permissions[3] = *((file_stat.st_mode & S_IXUSR) ? "x" : "-");
permissions[4] = *((file_stat.st_mode & S_IRGRP) ? "r" : "-");
permissions[5] = *((file_stat.st_mode & S_IWGRP) ? "w" : "-");
permissions[6] = *((file_stat.st_mode & S_IXGRP) ? "x" : "-");
permissions[7] = *((file_stat.st_mode & S_IROTH) ? "r" : "-");
permissions[8] = *((file_stat.st_mode & S_IWOTH) ? "w" : "-");
permissions[9] = *((file_stat.st_mode & S_IXOTH) ? "x" : "-");
permissions[10] = '\0';
return (permissions);
}
void dir_content(char *path)
{
char *permissions;
DIR *dir;
struct dirent *sd;
struct stat fstat;
dir = opendir(path);
if (dir == NULL)
return ;
while ((sd = readdir(dir)) != NULL)
{
stat(sd->d_name, &fstat);
printf("%i\n",stat(sd->d_name, &fstat));
if (sd->d_name[0] != '.')
{
printf("%s ", g_permissions(fstat, permissions));
printf("%s\n", sd->d_name);
}
}
closedir(dir);
}
int main(int ac, char **av)
{
char *test;
dir_content(av[1]);
return (0);
}
感谢您的帮助,对不起我的英语不好!
答案 0 :(得分:0)
您需要更改工作目录,这是答案https://stackoverflow.com/a/5126055/6416635
export interface IBurgerProps {
ingredients: {
salad?: number,
bacon?: number,
cheese?: number,
meat?: number
}
}
const burger = (props: IBurgerProps) =>{
const transformedIngredients = Object.keys(props.ingredients).map(igKey=> {
return [...Array(props.ingredients[igKey])].map((_, i) => {
<BurgerIngredient key={igKey + i} type={igKey}/>
})
});