Linux擷取目前使用者資訊函數__Oracle

來源:互聯網
上載者:User

http://www.cnblogs.com/dirt2/p/5999842.html

轉自:http://net.pku.edu.cn/~yhf/linux_c/function/07.html 

 




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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.