Linux gets the current user information function __oracle

Source: Internet
Author: User

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

Turn from: http://net.pku.edu.cn/~yhf/linux_c/function/07.html




Endgrent (Close group file)
Related functions Getgrent,setgrent
Table header File #include <grp.h>
#include <sys/types.h>
Defining functions void endgrent (void);
Function description Endgrent () is used to close the password file opened by Getgrent ().
return value
Additional Instructions
Example Please refer to getgrent () and Setgrent ().


Endpwent (Close password file)
Related functions Getpwent,setpwent
Table header File #include <pwd.h>
#include <sys/types.h>
Defining functions void endpwent (void);
Function description Endpwent () is used to close the password file opened by Getpwent ().
return value
Additional Instructions
Example Please refer to getpwent () and Setpwent ().


Endutent (Close utmp file)
Related functions Getutent,setutent
Table header File #include <utmp.h>
Defining functions void endutent (void);
Function description Endutent () is used to close the Utmp file that was opened by Getutent.
return value
Additional Instructions
Example Please refer to getutent ().


Fgetgrent (read group format from the specified file)
Related functions Fgetpwent
Table header File #include <grp.h>
#include <stdio.h>
#include <sys/types.h>
Defining functions struct Group * getgrent (FILE * stream);
Function description Fgetgrent () reads a row of data from the file specified by the parameter stream and returns the data in the group structure. The file specified by the parameter stream must be in the same format as, Etc/group. Group structure definition please refer to getgrent ().
return value Returns the group structure data, or null if returned, indicating no data, or an error occurred.
Example #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);
}
Perform 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 (read password format from specified file)
Related functions Fgetgrent
Table header File #include <pwd.h>
#include <stdio.h>
#include <sys/types.h>
Defining functions struct passwd * fgetpwent (FILE *stream);
Function description Fgetpwent () reads a row of data from the file specified by the parameter stream, and then returns the data as a passwd structure. The file specified by the parameter stream must be in the same format as/etc/passwd. passwd structure definition refer to getpwent ().
return value Returns the passwd structure data, if returned null indicates no data, or an error occurred.
Example #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);
}
}
Perform 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.