直接使用geteuid()得到的是当前用户的编号,要得到用户名,还需要到/etc/passwd中去取得相应编号的用户名
#include <unistd.h> 【相关文章:自己动手编写Eclipse扩展点】
程序如下 【扩展阅读:《dbXML 程序员手册_ 2.0_20】
#include <stdio.h> 【扩展信息:大家来看Borland的Delphi9官】 #include <sys/types.h> #include <sys/stat.h> #include <dirent.h> #include <fcntl.h>#define max 8192
#define umax 128int slip(char *,char *,char*);
int char2int(char *);int main()
{ int fp; file* stream; uid_t cuser; char temp[umax][max]; char fname; int i=0; char cname[20]; char userid[10]; cuser=geteuid(); if((stream=fopen("/etc/passwd","r"))==null)exit(1); while((fname=fgetc(stream))!=eof) { temp[i][0]=fname; if(fgets(&temp[i++][1],max,stream)==null)exit(1); } for(i=0;i<umax&&temp[i][0];i++) { if(slip(temp[i],cname,userid)==0)exit(1); if(cuser==char2int(userid))break; ... 下一页