Time of Update: 2017-01-19
C語言fchdir()函數:改變當前工作目錄標頭檔:#include <unistd.h>定義函數:int fchdir(int fd);函數說明:fchdir()用來將當前的工作目錄改變成以參數fd 所指的檔案描述詞。傳回值:執行成功則返回 0, 失敗返回-1, errno 為錯誤碼.範例#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include
Time of Update: 2017-01-19
C語言telldir()函數:取得目錄流的讀取位置標頭檔: #include <dirent.h>定義函數:off_t telldir(DIR *dir);函數說明:telldir()返回參數dir 目錄流目前的讀取位置. 此傳回值代表距離目錄檔案開頭的位移量傳回值返回下個讀取位置, 有錯誤發生時返回-1.錯誤碼:EBADF 參數dir 為無效的目錄流。範例#include <sys/types.h>#include <dirent.h>#include
Time of Update: 2017-01-19
C語言utime()函數:修改檔案的存取時間和更改時間標頭檔:#include <sys/types.h> #include <utime.h>定義函數:int utime(const char * filename, struct utimbuf * buf);函數說明:utime()用來修改參數filename 檔案所屬的inode 存取時間。結構utimbuf 定義如下:struct utimbuf{ time_t actime; time_t
Time of Update: 2017-01-19
C語言link()函數:建立檔案串連標頭檔:#include <unistd.h>定義函數:int link (const char * oldpath, const char * newpath);函數說明:link()以參數newpath 指定的名稱來建立一個新的串連(硬串連)到參數oldpath 所指定的已存在檔案. 如果參數newpath 指定的名稱為一已存在的檔案則不會建立串連.傳回值:成功則返回0, 失敗返回-1,
Time of Update: 2017-01-19
C語言rename()函數:重新命名檔案或目錄標頭檔:#include <stdio.h>函數rename()用於重新命名檔案、改變檔案路徑或更改目錄名稱,其原型為 int rename(char * oldname, char * newname);【參數】oldname為舊檔案名稱,newname為新檔案名稱。【傳回值】修改檔案名稱成功則返回0,否則返回-1。重新命名檔案: 如果newname指定的檔案存在,則會被刪除。
Time of Update: 2017-01-19
C語言opendir()函數:開啟目錄函式標頭檔:#include <sys/types.h> #include <dirent.h>定義函數:DIR * opendir(const char * name);函數說明:opendir()用來開啟參數name 指定的目錄, 並返回DIR*形態的目錄流, 和open()類似, 接下來對目錄的讀取和搜尋都要使用此傳回值.傳回值:成功則返回DIR* 型態的目錄流, 開啟失敗則返回NULL.錯誤碼:1、EACCESS
Time of Update: 2017-01-19
C語言truncate()函數:改變檔案大小標頭檔:#include <unistd.h>定義函數:int truncate(const char * path, off_t length);函數說明:truncate()會將參數path 指定的檔案大小改為參數length 指定的大小. 如果原來的檔案大小比參數length 大, 則超過的部分會被刪去.傳回值:執行成功則返回0, 失敗返回-1, 錯誤原因存於errno.錯誤碼:1、EACCESS 參數path 所指定的檔案無法存取。
Time of Update: 2017-01-19
C語言getcwd()函數:取得當前的工作目錄標頭檔:#include <unistd.h>定義函數:char * getcwd(char * buf, size_t size);函數說明:getcwd()會將當前的工作目錄絕對路徑複製到參數buf 所指的記憶體空間,參數size 為buf 的空間大小。註:1、在調用此函數時,buf 所指的記憶體空間要足夠大。若工作目錄絕對路徑的字串長度超過參數size 大小,則返回NULL,errno 的值則為ERANGE。2、倘若參數buf
Time of Update: 2017-01-19
C語言chmod()函數:修改檔案許可權標頭檔:#include <sys/types.h> #include <sys/stat.h>定義函數:int chmod(const char * path, mode_t mode);函數說明:chmod()會依參數mode 許可權來更改參數path 指定檔案的許可權。參數 mode 有下列數種組合:1、S_ISUID 04000 檔案的 (set user-id on execution)位2、S_ISGID 02000
Time of Update: 2017-01-19
C語言system()函數:執行shell命令標頭檔: #include <stdlib.h>定義函數:int system(const char * string);函數說明:system()會調用fork()產生子進程, 由子進程來調用/bin/sh-c string 來執行參數string 字串所代表的命令, 此命令執行完後隨即返回原調用的進程. 在調用system()期間SIGCHLD 訊號會被暫時擱置,SIGINT 和SIGQUIT 訊號則會被忽略.傳回值:1、如果
Time of Update: 2017-01-19
C語言setpriority()函數:設定程式進程執行優先權標頭檔:#include <sys/time.h> #include <sys/resource.h>定義函數:int setpriority(int which, int who, int prio);函數說明:setpriority()可用來設定進程、進程組和使用者的進程執行優先權。參數which 有三種數值, 參數who 則依which 值有不同定義。which who
Time of Update: 2017-01-19
C語言sscanf()函數:從字串中讀取指定格式的資料標頭檔:#include <stdio.h>sscanf()函數用於從字串中讀取指定格式的資料,其原型如下: int sscanf (char *str, char * format [, argument,
Time of Update: 2017-01-19
C語言fscanf()函數:輸入函數(比較常用)標頭檔:#include <stdio.h>定義函數:int fscanf(FILE * stream, const char *format, ...);函數說明:fscanf()會自參數stream 的檔案流中讀取字串, 再根據參數format 字串來轉換並格式化資料。格式轉換形式請參考scanf(). 轉換後的結構存於對應的參數內。傳回值:成功則返回參數數目, 失敗則返回-1, 錯誤原因存於errno 中。範例#include &
Time of Update: 2017-01-19
C語言wait()函數:結束(中斷)進程函數(常用)標頭檔:#include <sys/types.h> #include <sys/wait.h>定義函數:pid_t wait (int * status);函數說明:wait()會暫時停止目前進程的執行, 直到有訊號來到或子進程結束. 如果在調用wait()時子進程已經結束, 則wait()會立即返回子進程結束狀態值. 子進程的結束狀態值會由參數status 返回, 而子進程的進程識別碼也會一快返回.
Time of Update: 2017-01-19
C語言getpid()函數:擷取進程識別碼標頭檔:#include <unistd.h>定義函數:pid_t getpid(void);函數說明:getpid ()用來取得目前進程的進程識別碼,許多程式利用取到的此值來建立臨時檔案, 以避免臨時檔案相同帶來的問題。傳回值:目前進程的進程識別碼範例#include <unistd.h>main(){ printf("pid=%d\n", getpid());}執行:pid=1494 /*每次執行結果都不一定相同
Time of Update: 2017-01-19
C語言execv()函數:執行檔案函數標頭檔: #include <unistd.h>定義函數:int execv (const char * path, char * const argv[]);函數說明:execv()用來執行參數path 字串所代表的檔案路徑, 與execl()不同的地方在於execve()只需兩個參數, 第二個參數利用數組指標來傳遞給執行檔案.傳回值:如果執行成功則函數不會返回, 執行失敗則直接返回-1, 失敗原因存於errno 中.錯誤碼:請參考
Time of Update: 2017-01-19
C語言_exit()函數:結束進程執行標頭檔:#include <unistd.h>定義函數:void _exit(int status);函數說明:_exit()用來立刻結束目前進程的執行, 並把參數status 返回給父進程, 並關閉未關閉的檔案. 此函數調用後不會返回, 並且會傳遞SIGCHLD 訊號給父進程, 父進程可以由wait 函數取得子進程結束狀態.附加說明:_exit ()不會處理標準I/O 緩衝區, 如要更新緩衝區請使用exit ().C語言on_exit()函數:
Time of Update: 2017-01-19
C語言setlinebuf()函數:設定檔案流為線性緩衝區標頭檔:#include <stdio.h>定義函數:void setlinebuf(FILE * stream);函數說明:setlinebuf()用來設定檔案流以換行為依據的無緩衝IO. 相當於調用:setvbuf(stream, (char*)NULL, _IOLBF, 0);請參考setvbuf().C語言utmpname()函數:設定檔案路徑標頭檔:#include <utmp.h>定義函數:void
Time of Update: 2017-01-19
C語言freopen()函數:開啟檔案函數,並獲得檔案控制代碼標頭檔:#include <stdio.h>定義函數:FILE * freopen(const char * path, const char * mode, FILE * stream);函數說明:參數 path 字串包含欲開啟的檔案路徑及檔案名稱。參數mode 請參考fopen()說明.。參數stream 為已開啟的檔案指標. Freopen()會將原stream 所開啟的檔案流關閉, 然後開啟參數path
Time of Update: 2017-01-19
C語言setbuf()函數:把緩衝區與流相關聯標頭檔:#include <stdio.h>函數setbuf()用於將指定緩衝區與特定的檔案流相關聯,實現操作緩衝區時直接操作檔案流的功能。其原型如下:void setbuf(FILE * stream, char * buf);【參數】stream為檔案流指標,buf為緩衝區的起始地址。如果參數buf 為NULL 指標,則為無緩衝,setbuf()相當於調用setvbuf(stream, buf, buf ? _IOFBF :