亚洲韩日午夜视频,欧美日韩在线精品一区二区三区,韩国超清无码一区二区三区,亚洲国产成人影院播放,久草新在线,在线看片AV色

您好,歡迎來到思海網(wǎng)絡(luò),我們將竭誠(chéng)為您提供優(yōu)質(zhì)的服務(wù)! 誠(chéng)征網(wǎng)絡(luò)推廣 | 網(wǎng)站備案 | 幫助中心 | 軟件下載 | 購(gòu)買流程 | 付款方式 | 聯(lián)系我們 [ 會(huì)員登錄/注冊(cè) ]
促銷推廣
客服中心
業(yè)務(wù)咨詢
有事點(diǎn)擊這里…  531199185
有事點(diǎn)擊這里…  61352289
點(diǎn)擊這里給我發(fā)消息  81721488
有事點(diǎn)擊這里…  376585780
有事點(diǎn)擊這里…  872642803
有事點(diǎn)擊這里…  459248018
有事點(diǎn)擊這里…  61352288
有事點(diǎn)擊這里…  380791050
技術(shù)支持
有事點(diǎn)擊這里…  714236853
有事點(diǎn)擊這里…  719304487
有事點(diǎn)擊這里…  1208894568
有事點(diǎn)擊這里…  61352289
在線客服
有事點(diǎn)擊這里…  531199185
有事點(diǎn)擊這里…  61352288
有事點(diǎn)擊這里…  983054746
有事點(diǎn)擊這里…  893984210
當(dāng)前位置:首頁(yè) >> 技術(shù)文章 >> 文章瀏覽
技術(shù)文章

unix/Linux低級(jí)IO函數(shù)的用法

添加時(shí)間:2014-1-3 17:48:24  添加: 思海網(wǎng)絡(luò) 

unix/Linux 低級(jí)IO函數(shù)的用法,必須掌握

    寫module ,必要的應(yīng)用編程知識(shí)是應(yīng)該要有的, 否則 ,怎么寫應(yīng)用程序來測(cè)試你的module或者driver呢?

    而且最主要的是 , 了解上層調(diào)用的接口, 你就明白了上層的開發(fā)者需要什么, 自己才好實(shí)現(xiàn)什么。

    把手里的看書的事情都放下, 先把 Unix環(huán)境高級(jí)編程這本書 的第三章 徹底搞熟它

    內(nèi)容包括:

    open() ,尤其是各種常見的參數(shù),到底是什么意思, 比如常用創(chuàng)建一個(gè)空文件: fd = open("/tmp/xx.txt",O_RDWR | O_CREAT | O_TRUNC);

    讀一個(gè)文件,fd = open("/dev/hello",O_RDONLY );

    如果就是要寫一個(gè)既有的文件,fd = open("/dev/hello",O_WRONLY );

    具體的參數(shù): man 2 open

    read(),

    write()

    ioctl()  ,這個(gè)最重要。

    lseek() , 文件指針移動(dòng)

    比如下面的例子:

    就是簡(jiǎn)單的讀一個(gè)文件:

    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>

    int main(int argc,char **argv)
    {
            int fd = 0;
            int pid = 0;
            char buffer[20] = {'\0'};
            char *read_buffer[20] = {'\0'};

            //fd = open("/dev/hello",O_RDWR | O_CREAT | O_TRUNC);
            fd = open("/dev/hello",O_RDONLY ); //| O_NONBLOCK);
            printf("fd=%d\n",fd);
            if(fd < 0) {
                    perror("/dev/hello");
                    return -1;
            }

            read(fd,read_buffer,sizeof(read_buffer)-1);
            printf("read_buffer=%s\n",read_buffer);


            close(fd);

            return 0;
    }

下面這個(gè)就是簡(jiǎn)單的寫一個(gè)文件 ,

    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>

    int main(int argc,char **argv)
    {
            int fd = 0;
            int pid = 0;
            char buffer[20] = {'\0'};
            char write_buffer[20] = {'\0'};

            strcpy(write_buffer,"zhanglinbao");

            fd = open("/dev/hello",O_RDWR | O_CREAT | O_TRUNC);
            //fd = open("/dev/hello",O_RDONLY);
            printf("fd=%d\n",fd);
            if(fd < 0) {
                    perror("/dev/hello");
                    return -1;
            }

            write(fd,write_buffer,sizeof(write_buffer)-1);

            close(fd);

            return 0;
    }

關(guān)鍵字:Linux、IO函數(shù)、高級(jí)編程

分享到:

頂部 】 【 關(guān)閉
版權(quán)所有:佛山思海電腦網(wǎng)絡(luò)有限公司 ©1998-2024 All Rights Reserved.
聯(lián)系電話:(0757)22630313、22633833
中華人民共和國(guó)增值電信業(yè)務(wù)經(jīng)營(yíng)許可證: 粵B1.B2-20030321 備案號(hào):粵B2-20030321-1
網(wǎng)站公安備案編號(hào):44060602000007 交互式欄目專項(xiàng)備案編號(hào):200303DD003  
察察 工商 網(wǎng)安 舉報(bào)有獎(jiǎng)  警警  手機(jī)打開網(wǎng)站