脚本宝典收集整理的这篇文章主要介绍了unix编程创建前缀固定的临时文件代码分享,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
参数:
pathname,存储临时文件的路径文件名,需要手动free()掉。
dir,临时文件的路径,如果TMPDIR环境变量不为空,则此参数被忽略,转而使用环境变量。
pfx,临时文件名的前缀,只使用前5个字符。
注:
创建的临时文件需要手动unlink()掉。
创建临时文件的函数
测试程序
int main(int argc,char **argv){
int fd;
char *path;
if(argc!=3)
err_quit(-1,"usage %s <dir> <prefix>",argv[0]);
fd=Make_temp_file(&path,argv[1][0]==' '?NULL:argv[1],argv[2][0]==' '?NULL:argv[2]);
err_msg("temporary file path:%s",path);
Close(fd);
Unlink(path);
free(path);
return EXIT_SUCCESS;
}
测试结果
以上是脚本宝典为你收集整理的unix编程创建前缀固定的临时文件代码分享全部内容,希望文章能够帮你解决unix编程创建前缀固定的临时文件代码分享所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。