在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
参数: 创建临时文件的函数 复制代码 代码如下: int Make_temp_file(char **pathname,const char *dir,const char *pfx){ char *ptr,*tmp; size_t len; int fd; debug_assert("Invalid pointer","Make_temp_file()",pathname); /*前缀只能是多于5字符*/ if(pfx && (len=strlen(pfx))>0){ tmp=(char*)Malloc((len>5?5:len)+1); strncpy(tmp,pfx,len>5?5:len); } else tmp=NULL; ptr=tempnam(dir,tmp); if(tmp)free(tmp); len=strlen(ptr); tmp=(char*)Malloc(len+6+1); if(snprintf(tmp,len+6+1,"%sXXXXXX",ptr)==-1) err_sys(errno,"snprintf() error"); free(ptr); fd=Mkstemp(tmp); *pathname=tmp; return fd; } 测试程序 复制代码 代码如下: #include "wrap_ext.h" int main(int argc,char **argv){ 测试结果 复制代码 代码如下: root@U-SERVER:/home/apu/sysinfo# ./tmpfile " " " " temporary file path:/tmp/fileq55hoF8swFfa root@U-SERVER:/home/apu/sysinfo# ll /tmp/fileq55hoF8swFfa ls: cannot access /tmp/fileq55hoF8swFfa: No such file or directory root@U-SERVER:/home/apu/sysinfo# ./tmpfile " " tmp_ temporary file path:/tmp/tmp_0rzhqozlthxW root@U-SERVER:/home/apu/sysinfo# ./tmpfile /home tmp_ temporary file path:/home/tmp_phzxvRrp33OL |
请发表评论