Skip to Content
LINUX系統程式設計 第二版
book

LINUX系統程式設計 第二版

by Robert Love
December 2013
Intermediate to advanced
496 pages
8h 57m
Chinese
GoTop Information, Inc.
Content preview from LINUX系統程式設計 第二版
緩衝式 I/O
|
89
取得當前串流位置
不同於
lseek()
fseek()
並不會傳回更新過的位置。因此另外提供了一個介面。
ftell()
函式可用於傳回
stream
的當前串流位置:
#include <stdio.h>
long ftell (FILE *stream);
發生錯誤時,它會傳回
-1
並把
errno
設定成適當的值。
此外,標準 I/O 程式庫還提供了
fgetpos()
#include <stdioh.h>
int fgetpos (FILE *stream, fpos_t *pos);
執行成功時,
fgetpos()
會傳回
0
並把
stream
的當前串流位置放入
pos
。執行失敗時,則
會傳回
-1
並把
errno
設定成適當的值。如同
fsetpos()
,之所以會提供
fgetpos()
只是因
為非 Linux 平台具有複雜的檔案位置資料型別。
出清一個串流
標準 I/O 程式庫提供了一個介面,可用於把用戶緩衝區寫出到核心,以確保經由
write()
寫入至串流的所有資料得以被出清。
fflush()
函式便提供了此一功能:
#include <stdio.h>
int fflush (FILE *stream);
調用此函式時,
stream
所指向之串流中任何未被寫出的資料,會被出清至核心。如果
stream
NULL
,行程中所開啟的所有輸入串流均會被出清。執行成功時,
fflush()
會傳
0
。執行失敗時,則會傳回
EOF
並把
errno
設定成適當的值。
欲瞭解
fflush()
所造成的影響,你必須瞭解「C 程式庫所維護的緩衝區」與「核心自己 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

優雅的SciPy|Python科學研究的美學

優雅的SciPy|Python科學研究的美學

Juan Nunez-Iglesias, Stéfan van der Walt, Harriet Dashnow
C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普

Publisher Resources

ISBN: 9789862769812