| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> c/c++ >> zai linux xia shi yong c yu yan cao zuo lin shi wen jian

zai linux xia shi yong c yu yan cao zuo lin shi wen jian

2008-06-01 02:05:29 编辑來源:互联网 评论
 
 
 
本文为【在linux下使用c语言操作临时文件】的拼音翻译版
  /******************************************************************
  * ben wen shou fa yu bbs.bluegem.org de CWorld qu
  * ben ren email:chenfei@sohu.com
  * ru zhuan zai ben wen , qing bao liu shou fa di he ben ren lian luo fang shi , yi fang bian jiao liu ,
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  xie xie !
  ******************************************************************/
   you shi cheng xu xu yao cun chu hen da liang de shu ju , huo zhe zai ji ge jin cheng jian jiao huan shu ju , zhe shi nin ke neng kao lv dao shi yong lin shi wen jian 。 shi yong lin shi wen jian yao kao lv ji ge wen ti :
  1、 bao zheng lin shi wen jian jian de wen jian ming bu hu zhu chong tu 。
  2、 bao zheng lin shi wen jian zhong nei rong bu bei qi ta yong hu huo zhe hei ke tou kan 、 shan chu he xiu gai 。
  suo yi zai linux xia you zhuan men chu li lin shi wen jian de han shu
  mkstemp han shu
   mkstemp han shu jiang zai xi tong zhong yi du yi wu er de wen jian ming chuang jian yi ge wen jian bing da kai , er qie zhi you dang qian yong hu cai you fang wen zhe ge lin shi wen jian de quan xian , dang qian yong hu dui zhe ge lin shi wen jian ke yi da kai bing jin xing du 、 xie cao zuo 。mkstemp han shu zhi you yi ge shen shu , zhe ge shen shu shi ge yi “XXXXXX” jie yi de fei kong zi fu chuan 。mkstemp han shu hui yong sui ji chan sheng de zi fu chuan ti huan “XXXXXX”, bao zheng le wen jian ming de wei yi xing 。 han shu fan hui yi ge wen jian miao shu fu , jia ru zhi xing shi bai fan hui -1。 zai glibc 2.0.6 yi ji geng zao de glibc ku zhong zhe ge wen jian de fang wen quan xian shi 0666 ,glibc 2.0.7 yi hou de ku zhe ge wen jian de fang wen quan xian shi 0600。
   dang lin shi wen jian wan cheng ta de shi ming jia ru bu ba ta qing chu gan jing ba huo zhe cheng xu you yu yi wai zai lin shi wen jian bei qing chu qian jiu yi jing tui chu , lin shi wen jian suo zai de mu lu hui sai man la ji 。 you yu mkstemp han shu chuang jian de lin shi wen jian bu neng zi dong shan chu ( qing shen kao xia wen zhong de tmpfile han shu )。 zhi xing wan mkstemp han shu hou yao tiao yong unlink han shu ,unlink han shu shan chu wen jian de mu lu ru kou , suo yi lin shi wen jian huan ke yi tong guo wen jian miao shu fu jin xing fang wen , zhi dao zui hou yi ge da kai de jin cheng guan bi wen jian cao zuo fu , huo zhe cheng xu tui chu hou lin shi wen jian bei zi dong che di di shan chu 。
  li cheng :
  zhi jie shi yong advanced linux PRogramming de li cheng , zhi ba zhu shi fan yi yi xia
  #include <stdlib.h>
  #include <unistd.h>
  /* A handle for a temporary file created with write_temp_file. In
  this implementation, it’s just a file descriptor. */
  /*write_temp_file shi ge cao zuo lin shi wen jian de ju bing , ben li zhong zhi shi ge wen jian miao shu fu */
  typedef int temp_file_handle;
  /* Writes LENGTH bytes from BUFFER into a temporary file. The
  temporary file is immediately unlinked. Returns a handle to the
  temporary file. */
  /* zai zhe han shu cong BUFFER zhong xiang lin shi wen jian xie ru LENGTH zi jie shu ju 。 lin shi wen jian zai gang yi chuang jian jiu bei shan chu diao 。 han shu hui fan hui lin shi wen jian de ju bing 。*/
  temp_file_handle write_temp_file (char* buffer, size_t length)
  {
  /* Create the filename and file. The XXXXXX will be replaced with
  characters that make the filename unique. */
  /* xin jian wen jian ming he wen jian , wen jian ming zhong de XXXXXX jiang bei sui ji zi fu chuan dai ti , yi bao zheng wen jian ming zai xi tong zhong de wei yi xing */
  char temp_filename[] = “/tmp/temp_file.XXXXXX”;
  int fd = mkstemp (temp_filename);
  /* Unlink the file immediately, so that it will be removed when the
  file descriptor is closed. */
  /* wen jian ma shang bei unlink, zhe yang zhi yao wen jian miao shu fu yi guan bi wen jian jiu hui bei zi dong shan chu */
  unlink (temp_filename);
  /* Write the number of bytes to the file first. */
  /* shou xian xie ru ji jiang xie ru shu ju de chang du */
  write (fd, &length, sizeof (length));
  /* Now write the data itself. */
  /* xie ru shu ju ben shen */
  write (fd, buffer, length);
  /* Use the file descriptor as the handle for the temporary file. */
  /* han shu fan hui wen jian miao shu fu , zuo wei lin shi wen jian de ju bing */
  return fd;
  }
  /* Reads the contents of a temporary file TEMP_FILE created with
  write_temp_file. The return value is a newly allocated buffer of
  those contents, which the caller must deallocate with free.
  *LENGTH is set to the size of the contents, in bytes. The
  temporary file is removed. */
  /* cong bei write_temp_file chuang jian de lin shi wen jian zhong du qu shu ju 。 fan hui zhi shi han you wen jian nei rong de xin shen qing dao de nei cun kuai , zhe kuai nei cun ying gai you tiao yong read_temp_file zhe shi fang 。
  *length shi lin shi wen jian zheng wen nei rong de chang du 。 zhi xing wan read_temp_file han shu hou lin shi wen jian bei che di shan chu */
  char* read_temp_file (temp_file_handle temp_file, size_t* length)
  {
  char* buffer;
  /* The TEMP_FILE handle is a file descriptor to the temporary file. */
  /*fd shi fang wen lin shi wen jian de wen jian miao shu fu */
  int fd = temp_file;
  /* Rewind to the beginning of the file. */
  /* ba wen jian zhi zhen zhi xiang wen jian kai tou */
  lseek (fd, 0, SEEK_SET);
  /* Read the size of the data in the temporary file. */
  /* huo de lin shi wen jian zheng wen chang du */
  read (fd, length, sizeof (*length));
  /* Allocate a buffer and read the data. */
  /* fen pei nei cun kuai , du qu shu ju */
  buffer = (char*) malloc (*length);
  read (fd, buffer, *length);
  /* Close the file descriptor, which will cause the temporary file to
  go away. */
  /* guan bi wen jian miao shu fu , lin shi wen jian bei che di shan chu */
  close (fd);
  return buffer;
  }
  
  
  tmpfile han shu
   jia ru nin shi yong C library I/O han shu , bing qie bing mei you ling yi ge cheng xu shi yong zhe ge lin shi wen jian ( bi zhe zhu : an wo de li jie shi zai tong yi jin cheng huo ju you fu zi guan xi de jin cheng zu zhong ), you ge geng jian jie de han shu ——tmpfile。tmpfile han shu chuang jian bing da kai yi ge lin shi wen jian , bing qie zi dong zhi xing le unlink le zhe ge lin shi wen jian 。tmpfile han shu fan hui yi ge wen jian miao shu fu , jia ru zhi xing shi bai fan hui NULL。 dang cheng xu zhi xing le fclose huo zhe tui chu shi , zi yuan bei shi fang 。
   linux xi tong zhong huan ti gong mktemp、 tmpnam、 he tempnam deng han shu , dan shi you yu jian zhuang xing he an quan fang mian li you bu jian yi shi yong ta men 。
在linux下使用c语言操作临时文件
geng duo nei rong qing kan C/C++ jin jie ji shu wen dang C++ bian cheng Linux wen jian xiang guan wen zhang zhuan ti , huo【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
/****************************************************************** * ben wen shou fa yu bbs.bluegem.org de CWorld qu * ben ren email:chenfei@sohu.com * ru zhuan zai ben wen , qing bao liu shou fa di he ben ren lian luo fang shi , yi fang bian jiao liu , xie xie ! ******************************************************************/ you shi cheng xu xu yao cun chu hen da liang de shu ju , huo zhe zai ji ge jin cheng jian jiao huan shu ju , zhe shi nin ke neng kao lv dao shi yong lin shi wen jian 。 shi yong lin shi wen jian yao kao lv ji ge wen ti : 1、 bao zheng lin shi wen jian jian de wen jian ming bu hu zhu chong tu 。 2、 bao zheng lin shi wen jian zhong nei rong bu bei qi ta yong hu huo zhe hei ke tou kan 、 shan chu he xiu gai 。 suo yi zai linux xia you zhuan men chu li lin shi wen jian de han shu mkstemp han shu mkstemp han shu jiang zai xi tong zhong yi du yi wu er de wen jian ming chuang jian yi ge wen jian bing da kai , er qie zhi you dang qian yong hu cai you fang wen zhe ge lin shi wen jian de quan xian , dang qian yong hu dui zhe ge lin shi wen jian ke yi da kai bing jin xing du 、 xie cao zuo 。mkstemp han shu zhi you yi ge shen shu , zhe ge shen shu shi ge yi “XXXXXX” jie yi de fei kong zi fu chuan 。mkstemp han shu hui yong sui ji chan sheng de zi fu chuan ti huan “XXXXXX”, bao zheng le wen jian ming de wei yi xing 。 han shu fan hui yi ge wen jian miao shu fu , jia ru zhi xing shi bai fan hui -1。 zai glibc 2.0.6 yi ji geng zao de glibc ku zhong zhe ge wen jian de fang wen quan xian shi 0666 ,glibc 2.0.7 yi hou de ku zhe ge wen jian de fang wen quan xian shi 0600。 dang lin shi wen jian wan cheng ta de shi ming jia ru bu ba ta qing chu gan jing ba huo zhe cheng xu you yu yi wai zai lin shi wen jian bei qing chu qian jiu yi jing tui chu , lin shi wen jian suo zai de mu lu hui sai man la ji 。 you yu mkstemp han shu chuang jian de lin shi wen jian bu neng zi dong shan chu ( qing shen kao xia wen zhong de tmpfile han shu )。 zhi xing wan mkstemp han shu hou yao tiao yong unlink han shu ,unlink han shu shan chu wen jian de mu lu ru kou , suo yi lin shi wen jian huan ke yi tong guo wen jian miao shu fu jin xing fang wen , zhi dao zui hou yi ge da kai de jin cheng guan bi wen jian cao zuo fu , huo zhe cheng xu tui chu hou lin shi wen jian bei zi dong che di di shan chu 。 li cheng : zhi jie shi yong advanced linux PRogramming de li cheng , zhi ba zhu shi fan yi yi xia #include <stdlib.h> #include <unistd.h> /* A handle for a temporary file created with write_temp_file. In this implementation, it’s just a file descriptor. */ /*write_temp_file shi ge cao zuo lin shi wen jian de ju bing , ben li zhong zhi shi ge wen jian miao shu fu */ typedef int temp_file_handle; /* Writes LENGTH bytes from BUFFER into a temporary file. The temporary file is immediately unlinked. Returns a handle to the temporary file. */ /* zai zhe han shu cong BUFFER zhong xiang lin shi wen jian xie ru LENGTH zi jie shu ju 。 lin shi wen jian zai gang yi chuang jian jiu bei shan chu diao 。 han shu hui fan hui lin shi wen jian de ju bing 。*/ temp_file_handle write_temp_file (char* buffer, size_t length) { /* Create the filename and file. The XXXXXX will be replaced with characters that make the filename unique. */ /* xin jian wen jian ming he wen jian , wen jian ming zhong de XXXXXX jiang bei sui ji zi fu chuan dai ti , yi bao zheng wen jian ming zai xi tong zhong de wei yi xing */ char temp_filename[] = “/tmp/temp_file.XXXXXX”; int fd = mkstemp (temp_filename); /* Unlink the file immediately, so that it will be removed when the file descriptor is closed. */ /* wen jian ma shang bei unlink, zhe yang zhi yao wen jian miao shu fu yi guan bi wen jian jiu hui bei zi dong shan chu */ unlink (temp_filename); /* Write the number of bytes to the file first. */ /* shou xian xie ru ji jiang xie ru shu ju de chang du */ write (fd, &length, sizeof (length)); /* Now write the data itself. */ /* xie ru shu ju ben shen */ write (fd, buffer, length); /* Use the file descriptor as the handle for the temporary file. */ /* han shu fan hui wen jian miao shu fu , zuo wei lin shi wen jian de ju bing */ return fd; } /* Reads the contents of a temporary file TEMP_FILE created with write_temp_file. The return value is a newly allocated buffer of those contents, which the caller must deallocate with free. *LENGTH is set to the size of the contents, in bytes. The temporary file is removed. */ /* cong bei write_temp_file chuang jian de lin shi wen jian zhong du qu shu ju 。 fan hui zhi shi han you wen jian nei rong de xin shen qing dao de nei cun kuai , zhe kuai nei cun ying gai you tiao yong read_temp_file zhe shi fang 。 *length shi lin shi wen jian zheng wen nei rong de chang du 。 zhi xing wan read_temp_file han shu hou lin shi wen jian bei che di shan chu */ char* read_temp_file (temp_file_handle temp_file, size_t* length) { char* buffer; /* The TEMP_FILE handle is a file descriptor to the temporary file. */ /*fd shi fang wen lin shi wen jian de wen jian miao shu fu */ int fd = temp_file; /* Rewind to the beginning of the file. */ /* ba wen jian zhi zhen zhi xiang wen jian kai tou */ lseek (fd, 0, SEEK_SET); /* Read the size of the data in the temporary file. */ /* huo de lin shi wen jian zheng wen chang du */ read (fd, length, sizeof (*length)); /* Allocate a buffer and read the data. */ /* fen pei nei cun kuai , du qu shu ju */ buffer = (char*) malloc (*length); read (fd, buffer, *length); /* Close the file descriptor, which will cause the temporary file to go away. */ /* guan bi wen jian miao shu fu , lin shi wen jian bei che di shan chu */ close (fd); return buffer; } tmpfile han shu jia ru nin shi yong C library I/O han shu , bing qie bing mei you ling yi ge cheng xu shi yong zhe ge lin shi wen jian ( bi zhe zhu : an wo de li jie shi zai tong yi jin cheng huo ju you fu zi guan xi de jin cheng zu zhong ), you ge geng jian jie de han shu ——tmpfile。tmpfile han shu chuang jian bing da kai yi ge lin shi wen jian , bing qie zi dong zhi xing le unlink le zhe ge lin shi wen jian 。tmpfile han shu fan hui yi ge wen jian miao shu fu , jia ru zhi xing shi bai fan hui NULL。 dang cheng xu zhi xing le fclose huo zhe tui chu shi , zi yuan bei shi fang 。 linux xi tong zhong huan ti gong mktemp、 tmpnam、 he tempnam deng han shu , dan shi you yu jian zhuang xing he an quan fang mian li you bu jian yi shi yong ta men 。 [url=http://www.wangchao.net.cn/bbs/pydetail_1785351.html][img]http://image.wangchao.net.cn/it/1323423798211.gif[/img][/url] geng duo nei rong qing kan C/C++ jin jie ji shu wen dang C++ bian cheng Linux wen jian xiang guan wen zhang zhuan ti , huo
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
桌球宝贝_性感在蔓延(3)
桌球宝贝_性感在蔓延(2)
银杏树下清纯女孩(9)
银杏树下清纯女孩(8)
痞子的甘南日记
疑是银河落九天
雪域坝上四——纯美色
冬日恋歌——西城杨柳弄轻柔
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有