| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
fmms
12年前发布

C语言日志、事务API libjio

     <p>libjio是一个C库做日志,交易为导向的I/O它提供了一个类UNIX的文件操作功能(如打开,读取和写入) ,这是装在一个交易框架,以使文件操作可以提交或回滚是必要的。这是非侵入性,原子,和线程安全的,具有快速崩溃恢复。</p>    <p>示例代码:</p>    <pre class="brush:c#; toolbar: true; auto-links: false;">#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <errno.h> #include <string.h> #include <libjio.h>  #define FILENAME "test1" #define TEXT "Hello world!\n"  int main(void) {     int r;     struct jfs file;     struct jtrans trans;     struct jfsck_result result;      /* check the file is OK */     jfsck(FILENAME, NULL, &result);     jfsck_cleanup(FILENAME, NULL);      /* and open it */     r = jopen(&file, FILENAME, O_RDWR | O_CREAT | O_TRUNC, 0600, 0);     if (r < 0) {         perror("jopen");         return 1;     }      /* write two "Hello world"s next to each other */     jtrans_init(&file, &trans);     jtrans_add(&trans, TEXT, strlen(TEXT), 0);     jtrans_add(&trans, TEXT, strlen(TEXT), strlen(TEXT));     r = jtrans_commit(&trans);     if (r < 0) {         perror("jtrans_commit");         return 1;     }      /* at this point the file has "Hello world!\nHello world!\n" */      /* now we rollback */     r = jtrans_rollback(&trans);     if (r < 0) {         perror("jtrans_rollback");         return 1;     }      /* and now the file is empty! */      jtrans_free(&trans);     jclose(&file);     return 0; }</pre>    <p><strong>项目主页:</strong><a href="http://www.open-open.com/lib/view/home/1326898446140" target="_blank">http://www.open-open.com/lib/view/home/1326898446140</a></p>     
 本文由用户 fmms 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1326898446140.html
C语言 C/C++开发