zoukankan      html  css  js  c++  java
  • mkstemp用法

    基本IO函数的使用(mkstemp)

    mkstemp(建立唯一的临时文件)
    表头文件 #include<stdlib.h>
    定义函数 int mkstemp(char * template);
    函数说明:
         mkstemp()用来建立唯一的临时文件。参数 template 所指的文件
         名称字符串中最后六个字符必须是 XXXXXX。mkstemp()会以可
         读写模式和 0600 权限来打开该文件,如果该文件不存在则会建立
         该文件。打开该文件后其文件描述词会返回。
         文件顺利打开后返回可读写的文件描述词。若果文件打开失败则返
         回 NULL,并把错误代码存在 errno 中。

    错误代码
         EINVAL 参数 template 字符串最后六个字符非 XXXXXX。
         EEXIST 无法建立临时文件。
        
    附加说明
        参数 template 所指的文件名称字符串必须声明为数组,如:
            char template[ ] =”template-XXXXXX”;
             千万不可以使用下列的表达方式
            char *template = “template-XXXXXX”;

    1 #include <stdlib.h>
    2 #include <stdio.h>
    3
    4  int main(void)
    5 {
    6 char temp[] = "tempfile_XXXXXX";
    7 char content[] = "This is written by the program.";
    8 int fd;
    9 fd = mkstemp( temp );
    10 write( fd, content, sizeof(content) );
    11 printf( "The template file name is %s\n", temp );
    12 close( fd );
    13 return 0;
    14 }
    15

  • 相关阅读:
    Linux Mint---shutter截图软件
    Linux Mint---fcitx中文,日语输入法
    Linux Mint---安装docky
    Linux Mint---开启桌面三维特效
    Linux Mint---ATI显卡驱动安装篇
    Linux Mint---更新软件源
    Spring Cloud 微服务服务间调用session共享问题
    Jooq批量插入 batch
    idea安装SonarLint语法检测插件
    JVM到底是什么?
  • 原文地址:https://www.cnblogs.com/BloodAndBone/p/1938022.html
Copyright © 2011-2022 走看看