系统调用3--close

来源:互联网 发布:阿里云招聘官网首页 编辑:程序博客网 时间:2024/06/06 15:35
#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>/*******************************file:close.c*author:QG*time:2015-05-10*note:********************************/int main(){    char *pt = "./123.txt";    int a = 0;    int b = 0;    a = open(pt,O_WRONLY);    if(a < 0)    {        printf("open file is fail!\n");    }    else    {        printf("open file is success,descriptor is %d!\n",a);    }        /**************************    *func:int close(int fd);    *parametre: fd is the file's descriptor which will be closed!    *return:close() returns zero on success, on error ,-1 is returned.    *function:    ****************************/    b = close(a);    if(b == 0)    {        printf("close file is success!\n");    }    else    {        printf("close file is fail!\n");    }    return 0;}

0 0
原创粉丝点击