find_home_user.c

来自「一个C语言写的快速贝叶斯垃圾邮件过滤工具」· C语言 代码 · 共 41 行

C
41
字号
/** \file find_home_user.c figure out the home dir of given user *//* (C) 2002,2003,2006 by Matthias Andree <matthias.andree@gmx.de> * (C) 2003 by David Relson <relson@osagesoftware.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * General Public License for more details, it is in the file named * COPYING. *//* $Id: find_home_user.c,v 1.3 2006/07/08 14:56:40 m-a Exp $ */#include "system.h"#include <stdlib.h>#include <pwd.h>#include <sys/types.h>#include "find_home.h"/** This function will try to figure out the home directory of the user * whose name is given as argument. * * This function returns NULL in case of failure. */const char *find_home_user(const char *username) {    struct passwd *pw;    pw = getpwnam(username);    if (pw != NULL) {	return pw -> pw_dir;    }    return NULL;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?