使用mknod()创建目录 [英] Creating directory with mknod()

查看:181
本文介绍了使用mknod()创建目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 mknod()创建目录(不允许在我的计算机上使用 mkdir()的情况),我将从某个目录中调用该程序,并在上一个目录中介绍应在其中创建新目录的路径。

I need to create a directory using mknod() (use of mkdir() is not allow in my case), I would call the program from a certain directory and introduce the path where the new dir should be created inside the previous one.

例如:如果我是 / home / user / test / 且在 test内 / level1 / ,我想在<$ c内创建目录 level2 $ c> level1 ,因此我将传递参数 / level1 / level2 /

Ex: If I'm /home/user/test/ and inside test there is /level1/, I want to create the directory level2 inside level1, so I would pass the argument /level1/level2/

创建管道时,下面的代码可以工作,但是当我将模式更改为 S_IFDIR 时,它什么也没做。

I have the following code that works when I create a pipe,but when I change the mode to S_IFDIR, it doesn't do anything.

 #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>

void main(int argc,char *argv[]){
    int status;
    if ((status  = mknod(argv[1], S_IFDIR,0)) == 1){
        printf("error\n" );
    }
    exit(0);

}


推荐答案

mknod 通常用于创建设备节点(特殊目录)。

mknod is normally used for creating device nodes (special directories).

但是,某些操作系统确实支持使用以下命令创建常规目录 mknod (QNX)。

However, some OSs do support creating a regular directory with mknod (QNX).

您是否在使用的操作系统上检查了手册页中的mknod?我非常确定 S_IFDIR mknod 的不可移植选项。

Did you check the man page for mknod on the OS you're using? I am quite sure that S_IFDIR is a non-portable option for mknod.

这篇关于使用mknod()创建目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆