#include <stdio.h>
#include <stdlib.h>
#include <error.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
// 用unlink创建一个匿名临时文件
int main(int argc, char *argv[])
{
int fd;
fd = open("./tmpfile", O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd < 0)
{
perror("open()");
exit(1);
}
unlink("./tmpfile");
char buf[64];
strcpy(buf, "hello");
write(fd, buf, 64);
while ('q' != getchar())
{
system("cat ./tmpfile");
}
close(fd);
exit(0);
}
unlink创建匿名临时文件
最新推荐文章于 2024-07-20 22:11:56 发布