|
endgrent(關閉組檔案) |
| 相關函數 |
getgrent,setgrent |
| 表標頭檔 |
#include<grp.h> #include<sys/types.h> |
| 定義函數 |
void endgrent(void); |
| 函數說明 |
endgrent()用來關閉由getgrent()所開啟的密碼檔案。 |
| 傳回值 |
|
| 附加說明 |
|
| 範例 |
請參考getgrent()與setgrent()。 |
|
| |
endpwent(關閉密碼檔案) |
| 相關函數 |
getpwent,setpwent |
| 表標頭檔 |
#include<pwd.h> #include<sys/types.h> |
| 定義函數 |
void endpwent(void); |
| 函數說明 |
endpwent()用來關閉由getpwent()所開啟的密碼檔案。 |
| 傳回值 |
|
| 附加說明 |
|
| 範例 |
請參考getpwent()與setpwent()。 |
|
| |
endutent(關閉utmp 檔案) |
| 相關函數 |
getutent,setutent |
| 表標頭檔 |
#include<utmp.h> |
| 定義函數 |
void endutent(void); |
| 函數說明 |
endutent()用來關閉由getutent所開啟的utmp檔案。 |
| 傳回值 |
|
| 附加說明 |
|
| 範例 |
請參考getutent()。 |
|
| |
fgetgrent(從指定的檔案來讀取組格式) |
| 相關函數 |
fgetpwent |
| 表標頭檔 |
#include<grp.h> #include<stdio.h> #include<sys/types.h> |
| 定義函數 |
struct group * getgrent(FILE * stream); |
| 函數說明 |
fgetgrent()會從參數stream指定的檔案讀取一行資料,然後以group結構將該資料返回。參數stream所指定的檔案必須和、etc/group相同的格式。group結構定義請參考getgrent()。 |
| 傳回值 |
返回group結構資料,如果返回NULL則表示已無資料,或有錯誤發生。 |
| 範例 |
#include <grp.h> #include<sys/types.h> #include<stdio.h> main() { struct group *data; FILE *stream; int i; stream = fopen("/etc/group", "r"); while((data = fgetgrent(stream))!=0){ i=0; printf("%s :%s:%d :", data->gr_name,data->gr_passwd,data->gr_gid); while (data->gr_mem[i])printf("%s,",data->gr_mem[i++]); printf("\n"); } fclose(stream); } |
| 執行 |
root:x:0:root, bin:x:1:root,bin,daemon daemon:x:2:root,bin,daemon sys:x:3:root,bin,adm adm:x:4:root,adm,daemon tty:x:5 disk:x:6:root lp:x:7:daemon,lp mem:x:8 kmem:x:9 wheel:x:10:root mail:x:12:mail news:x:13:news uucp:x:14:uucp man:x:15 games:x:20 gopher:x:30 dip:x:40: ftp:x:50 nobody:x:99: |
|
| |
fgetpwent(從指定的檔案來讀取密碼格式) |
| 相關函數 |
fgetgrent |
| 表標頭檔 |
#include<pwd.h> #include<stdio.h> #include<sys/types.h> |
| 定義函數 |
struct passwd * fgetpwent(FILE *stream); |
| 函數說明 |
fgetpwent()會從參數stream指定的檔案讀取一行資料,然後以passwd結構將該資料返回。參數stream所指定的檔案必須和/etc/passwd相同的格式。passwd結構定義請參考getpwent()。 |
| 傳回值 |
返回passwd結構資料,如果返回NULL則表示已無資料,或有錯誤發生。 |
| 範例 |
#include<pwd.h> #include<sys/types.h> main() { struct passwd *user; FILE *stream; stream = fopen("/etc/passwd", "r"); while((user = fgetpwent(stream))!=0){ printf("%s:%d:%d:%s:%s:%s\n",user->pw_name,user->pw_uid,user->pw_gid,user->pw_gecos,user->pw_dir,user->pw_shell); } } |
| 執行 |
root:0:0:root:/root:/bin/bash bin:1:1:bin:/bin: daemon:2:2:daemon:/sbin: adm:3:4:adm:/var/adm: lp:4:7:lp:/var/spool/lpd: sync:5:0:sync:/sbin:/bin/sync shutdown:6:0:shutdown:/sbin:/sbin/shutdown halt:7:0:halt:/sbin:/sbin/halt mail:8:12:mail:/var/spool/mail: news:9:13:news:var/spool/news |