stdlibc/pwd: \!Read data from right file
[meinos.git] / apps / lib / stdlibc / pwd.c
blobda0154244585b0467f53ccb04a8ce7b1230f28de
1 /*
2 meinOS - A unix-like x86 microkernel operating system
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <sys/types.h>
20 #include <pwd.h>
21 #include <llist.h>
22 #include <stdio.h>
23 #include <stdlib.h>
25 static llist_t pwd_list = NULL;
26 static size_t pwd_idx = 0;
28 static void pwd_init() {
29 //char *filename;
30 //FILE *fd = fopen("/etc/passwd","r");
31 /// @todo Read from file and do some scanf or regex stuff
32 //fclose(fd);
35 struct passwd *getpwnam(const char *name) {
36 if (pwd_list==NULL) pwd_init();
38 size_t i;
39 struct passwd *pwd;
40 for (i=0;(pwd = llist_get(pwd_list,i));i++) {
41 if (strcmp(pwd->pw_name,name)==0) return pwd;
43 return NULL;
46 struct passwd *getpwuid(uid_t uid) {
47 if (pwd_list==NULL) pwd_init();
49 size_t i;
50 struct passwd *pwd;
51 for (i=0;(pwd = llist_get(pwd_list,i));i++) {
52 if (pwd->pw_uid==uid) return pwd;
54 return NULL;
57 struct passwd *getpwent() {
58 return llist_get(pwd_list,pwd_idx++);
61 void setpwent() {
62 pwd_idx = 0;