1 使用Linux的系統介面進行檔案的讀寫

2021-10-02 09:56:04 字數 1293 閱讀 1466

1、所用的主要函式介面

open函式

#include

#include

#include

intopen

(const

char

*pathname,

int flags)

;int

open

(const

char

*pathname,

int flags, mode_t mode)

;返回值:成功返回新分配的檔案描述符,出錯返回-

1並設定error

mode對應open函式來說,僅當建立新檔案時才使用第三個引數

read函式

#include

ssize_t read

(int feleds,

void

*buff, size_t nbytes)

;read函式從當前檔案偏移量處讀入指定的檔案內容

read函式會把引數feleds所指的檔案傳送nbytes個位元組到buff中

返回值:返回讀到的位元組數。若已到檔案尾為0,若出錯為-

1. 如果read成功,則返回讀到的位元組數。如已到檔案末尾,則返回0。

write函式

#include

ssize_t write

(int feleds,

const

void

*buff, size_t nbytes)

;write函式會把buff所指的記憶體寫入nbytes個位元組到feleds所指的檔案中。

返回值:若成功返回寫的位元組數,出錯返回-

1。

2、例子

#include

#include

#include

#include

#include

#include

intmain()

int fd1 =

open

("newfile.txt"

, o_creat | o_wronly,

0644);

if(fd1 ==-1

)char buf[2*

1024]=

; ssize_t n =

read

(fd, buf,

sizeof

(buf));

if(n ==-1

)while

(n >0)

return0;

}

使用fiddler進行介面測試

我們來說說如何使用fiddler做介面測試?測試準備,抓到相應的介面和入參或者找介面文件,我這裡就用聚合資料裡面的介面做樣例,介面如下 測試介面 請求引數 qq 1301791233 key ee9757f1b3fe186ec4deddcf7450266b 請求方式 get post 1 開啟fid...

使用Loadrunner進行http介面壓力測試

業務描述 在業務系統裡進行查詢操作,查詢的結果是通過請求http介面,從系統中處理並將結果以json字串返回。使用loadrunner對此類介面進行壓力測試並記錄相關的效能指標資料 一.安裝loadrunner 本次測試過程使用loadrunner 11.0版本。安裝loadrunner過程詳見.二...

linux與作業系統(1) 使用者介面

許多使用者認為他們在unix linux命令列介面上所見的就是真正的作業系統,實際上這只是乙個命令列直譯器,叫做shell。它是乙個用來接收使用者輸入命令並把它翻譯成指令的程式,是乙個介於使用者和底層作業系統之間的程式。它的目的是方便使用者使用核心,更重要的是保護核心不受使用者的破壞。shell和m...