setvbuf 中文man頁面

2021-01-11 51cto

NAME

setbuf, setbuffer, setlinebuf, setvbuf - 流緩衝操作  

SYNOPSIS 總覽

#include <stdio.h>

void setbuf(FILE *stream, char *buf);
void setbuffer(FILE *stream, char *buf, size_t size);
void setlinebuf(FILE *stream);
int setvbuf(FILE *stream, char *buf, int mode , size_t size);  

DESCRIPTION 描述

有三種類型的緩衝策略,它們是無緩衝,塊緩衝和行緩衝。當輸出流無緩衝時,信息在寫的同時出現於目標文件或終端上;當是塊緩衝時,字符被暫存,然後一起寫入;當是行緩衝時,字符被暫存,直到要輸出一個新行符,或者從任何與終端設備連接的流中 (典型的是 stdin) 讀取輸入時才輸出。函數 fflush(3) 可以用來強制提前輸出。(參見 fclose(3)) 通常所有文件都是塊緩衝的。當文件 I/O 操作在文件上發生時,將調用 malloc(3) ,獲得一個緩衝。如果流指向一個終端 (通常 stdout 都是這樣),那麼它是行緩衝的。標準錯誤流 stderr 默認總是無緩衝的。

函數 setvbuf 可以用在任何打開的流上,改變它的緩衝。參數 mode 必須是下列三個宏之一:

_IONBF 無緩衝 _IOLBF 行緩衝 _IOFBF 完全緩衝

除非是無緩衝的文件,否則參數 buf 應當指向一個長度至少為 size 字節的緩衝;這個緩衝將取代當前的緩衝。如果參數 buf 是 NULL ,只有這個模式會受到影響;下次 read 或 write 操作還將分配一個新的緩衝。函數 setvbuf 只能在打開一個流,還未對它進行任何其他操作之前使用。

其他三個函數調用是函數 setvbuf 的別名,函數 setbuf 與使用下列語句完全等價:

setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);

函數 setbuffer 與此相同,但是緩衝的長度由用戶決定,而不是由默認值 BUFSIZ 決定。函數 setlinebuf 與使用下列語句完全等價:

setvbuf(stream, (char *)NULL, _IOLBF, 0); RETURN VALUE 返回值

函數 setvbuf 成功執行時返回 0。它失敗時可能返回任何值,但是當 It can return any value on failure, but returns nonzero when mode 不正確,或者不能實現請求時,必須返回非零值。它在失敗時可能設置 errno 。其他函數沒有返回值。  

CONFORMING TO 標準參考

函數 setbuf 和 setvbuf 遵循 ANSI X3.159-1989 (``ANSI C'') 標準。  

BUGS

函數 setbuffer 和 setlinebuf 無法移植到 4.2BSD 之前的 BSD 版本,在 Linux 中僅在 libc 4.5.21 之後的系統中可用。在 4.2BSD 和 4.3BSD 系統中, setbuf 總是使用非最優的緩衝大小,應當避免使用它。 在 stream 被關閉時,必須確保 buf 和它指向的空間仍然存在。這通常發生在程序終止時。 例如,下列調用是非法的:

#include <stdio.h>int main(){ char buf[BUFSIZ]; setbuf(stdin, buf); printf("Hello, world!\n"); return 0;}

SEE ALSO 參見

fclose(3), fflush(3), fopen(3), fread(3), malloc(3), printf(3), puts(3)

NAME

setbuf, setbuffer, setlinebuf, setvbuf - stream buffering operations  

SYNOPSIS

#include <stdio.h>

void setbuf(FILE *stream, char *buf);
void setbuffer(FILE *stream, char *buf, size_t size);
void setlinebuf(FILE *stream);
int setvbuf(FILE *stream, char *buf, int mode , size_t size);  

DESCRIPTION

The three types of buffering available are unbuffered, block buffered, and line buffered. When an output stream is unbuffered, information appears on the destination file or terminal as soon as written; when it is block buffered many characters are saved up and written as a block; when it is line buffered characters are saved up until a newline is output or input is read from any stream attached to a terminal device (typically stdin). The function fflush(3) may be used to force the block out early. (See fclose(3).) Normally all files are block buffered. When the first I/O operation occurs on a file, malloc(3) is called, and a buffer is obtained. If a stream refers to a terminal (as stdout normally does) it is line buffered. The standard error stream stderr is always unbuffered by default.

The setvbuf function may be used on any open stream to change its buffer. The mode parameter must be one of the following three macros:

_IONBF unbuffered _IOLBF line buffered _IOFBF fully buffered

Except for unbuffered files, the buf argument should point to a buffer at least size bytes long; this buffer will be used instead of the current buffer. If the argument buf is NULL, only the mode is affected; a new buffer will be allocated on the next read or write operation. The setvbuf function may only be used after opening a stream and before any other operations have been performed on it.

The other three calls are, in effect, simply aliases for calls to setvbuf. The setbuf function is exactly equivalent to the call

setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);

The setbuffer function is the same, except that the size of the buffer is up to the caller, rather than being determined by the default BUFSIZ. The setlinebuf function is exactly equivalent to the call:

setvbuf(stream, (char *)NULL, _IOLBF, 0); RETURN VALUE

The function setvbuf returns 0 on success. It can return any value on failure, but returns nonzero when mode is invalid or the request cannot be honoured. It may set errno on failure. The other functions are void.  

CONFORMING TO

The setbuf and setvbuf functions conform to ANSI X3.159-1989 (``ANSI C'').  

BUGS

The setbuffer and setlinebuf functions are not portable to versions of BSD before 4.2BSD, and are available under Linux since libc 4.5.21. On 4.2BSD and 4.3BSD systems, setbuf always uses a suboptimal buffer size and should be avoided. You must make sure that both buf and the space it points to still exist by the time stream is closed, which also happens at program termination. For example, the following is illegal:

#include <stdio.h>int main(){ char buf[BUFSIZ]; setbuf(stdin, buf); printf("Hello, world!\n"); return 0;}

SEE ALSO

fclose(3), fflush(3), fopen(3), fread(3), malloc(3), printf(3), puts(3)

【責任編輯:

韓亞珊

TEL:(010)68476606】

相關焦點

  • CLOSE 中文man頁面
    CLOSE 中文man頁面 CLOSE 釋放和一個遊標關聯的資源。 一個遊標關閉後,不允許對其再做任何操作。一個不再使用的遊標應該關閉掉。
  • DROP INDEX 中文man頁面
    DROP INDEX 中文man頁面 DROP INDEX 從資料庫中刪除一個現存的索引。 要執行這個命令,你必須是索引的所有者。
  • START TRANSACTION 中文man頁面
    START TRANSACTION 中文man頁面 這條命令開始一個新的事務。如果聲明了隔離級別或者讀寫模式, 那麼新事務就使用這個特性,如同執行了 SET TRANSACTION [set_transaction(7)] 一樣。
  • pppd 中文man頁面
    Username/Password Incorrect" "" "at" OK "at&d0&c1" OK "atdt2468135" "name:" "^Umyuserid" "word:" "\qmypassword" "ispts" "\q^Uppp" "~-^Uppp-~" See the chat(8) man
  • stdout 中文man頁面
  • modinfo 中文man頁面
  • grep 中文man頁面
  • CREATE CONVERSION 中文man頁面
  • eMule-Project站點增加簡體中文頁面
    感謝阿pp的投遞:簡體中文作業系統用戶上eMule-project網站會被自動轉到簡體用戶頁面了.eMule-project
  • 首發中文?SE《復聯》遊戲新作上線中文倒計時頁面 - 3DMGAME
    而今日我們可以發現Square Enix赫然上線了遊戲的中文網站,並顯眼的給出了遊戲公布的倒計時,且該頁面支持簡體中文和繁體中文切換,這是否意味著此次的《漫威復仇者聯盟》官中已經給安排上了?
  • 模擬建造新遊《叢林之屋》上架Steam頁面 支持中文
    模擬建造新遊《叢林之屋》上架Steam頁面 支持中文 時間:2020-07-03 09:05:33 來源:Steam
  • 《賽博朋克2077》三張4K截圖 中文官網頁面更新
    《賽博朋克2077》三張4K截圖 中文官網頁面更新 《賽博朋克2077》三張4K截圖 中文官網頁面更新
  • No man is an island是什麼意思?
    No man is an island的英語能力口語訓練No man is an island是什麼意思?我們還是先用英語No man is an island做「把學過的英語用起來」「見英語說英語」的能力訓練吧。我不要你見英語No man is an island能「說」中文的能力,也不需要你今天學了英語No man is an island明天就有機會跟人說英語No man is an island(沒有人是座孤島)。
  • 首批火星地形地貌中文推薦譯名 中國天文學會官網可視化頁面入口地址
    首頁 > 動態 > 關鍵詞 > 火星最新資訊 > 正文 首批火星地形地貌中文推薦譯名 中國天文學會官網可視化頁面入口地址
  • 把英語讀成英語的能力:a man of importance什麼意思?
    把英語讀成英語的能力:a man of importance什麼意思?一、什麼是「英語閱讀」英能力訓練?這個能力是什麼?我們說的這個能力就是你閱讀時「對著英語說英語」的能力,而不是「對著英語說中文」。這個不叫做英語閱讀,這個叫做中文閱讀。二、注意英語詞彙裡有一種詞性轉換的現象。
  • 美國人說的I'm a man of my word是什麼意思?
    美國人說的I'm a man of my word是什麼意思?我們所有的「英語閱讀」,都可以歸結為回答一個問題:你的「英語閱讀」指的就是用中文「讀懂」英語,用中文意思去「懂得」英語在說什麼嗎?一、下面的英語a man of word時,你是讀」成中文,還是英語?1. Bob, I'm a man of my word.
  • 英語口語:one man's meat is another's poison
    英語口語:one man's meat is another's poison1) 把英語one man's meat is another's poison翻譯成中文理解,是「學習英語」:你終於「用」中文懂得英語one man's meat is another's poison
  • creeper aww man是什麼梗 Creeper接龍歌曲梗出處及中文意思
    creeper aww man是什麼梗?就好似接龍一樣,說出「creeper」,自然而然會說「aww man」,這是為什麼呢,大家都不知道是什麼意思,下面小編就為大家詳細介紹一下吧。Aw man,這是連起來的一句話,說了Creeper,就會有人不自覺地說出Aw man,就是好玩,一種樂趣。  由於《我的世界》裡的「creeper」梗火起來的,很多網友在抖音、貼吧、論壇、微博等自娛自樂著。  就類似與有人說了「窩窩頭,一塊錢四個」,就會有人不自覺地說出「嘿嘿」一樣的意思。
  • 關於「Man」的俚語
    2. man of letters 文人、作家、學者例句:Shakespeare was perhaps Britain's greatest man of letters.莎士比亞或許可以算是英國最偉大的作家。
  • Elementor教程-初識elementor-神奇的WordPress頁面生成器
    Elementor這是一款可以通過拖拽、點擊就可以完成wordpress站點設計的插件,同類似的插件也很多,比如Divi,Visual Composer,WPBeaverbuilder,Fusion Builder這些,每個我都嘗試過,也購買過付費的版本,最終還是覺得elementor,用起來比較順手,因為該產品是老外的,所以一直沒有比較好的中文教程