Blame tools/user_group.c

rpm-build 0a0c83
/*
rpm-build 0a0c83
  File: user_group.c
rpm-build 0a0c83
  (Linux Access Control List Management)
rpm-build 0a0c83
rpm-build 0a0c83
  Copyright (C) 1999, 2000
rpm-build 0a0c83
  Andreas Gruenbacher, <a.gruenbacher@bestbits.at>
rpm-build 0a0c83
 	
rpm-build 0a0c83
  This program is free software; you can redistribute it and/or modify
rpm-build 0a0c83
  it under the terms of the GNU General Public License as published by
rpm-build 0a0c83
  the Free Software Foundation; either version 2 of the License, or (at
rpm-build 0a0c83
  your option) any later version.
rpm-build 0a0c83
rpm-build 0a0c83
  This program is distributed in the hope that it will be useful, but
rpm-build 0a0c83
  WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build 0a0c83
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
rpm-build 0a0c83
  General Public License for more details.
rpm-build 0a0c83
rpm-build 0a0c83
  You should have received a copy of the GNU General Public License
rpm-build 0a0c83
  along with this library; if not, write to the Free Software
rpm-build 0a0c83
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
rpm-build 0a0c83
  USA.
rpm-build 0a0c83
*/
rpm-build 0a0c83
rpm-build 0a0c83
#include "config.h"
rpm-build 0a0c83
#include <stdlib.h>
rpm-build 0a0c83
#include <stdio.h>
rpm-build 0a0c83
#include "user_group.h"
rpm-build 0a0c83
rpm-build 0a0c83
rpm-build 0a0c83
const char *
rpm-build 0a0c83
user_name(uid_t uid, int numeric)
rpm-build 0a0c83
{
rpm-build 0a0c83
	struct passwd *passwd = numeric ? NULL : getpwuid(uid);
rpm-build 0a0c83
	static char uid_str[22];
rpm-build 0a0c83
	int ret;
rpm-build 0a0c83
rpm-build 0a0c83
	if (passwd != NULL)
rpm-build 0a0c83
		return passwd->pw_name;
rpm-build 0a0c83
	ret = snprintf(uid_str, sizeof(uid_str), "%ld", (long)uid);
rpm-build 0a0c83
	if (ret < 1 || (size_t)ret >= sizeof(uid_str))
rpm-build 0a0c83
		return "?";
rpm-build 0a0c83
	return uid_str;
rpm-build 0a0c83
}
rpm-build 0a0c83
rpm-build 0a0c83
rpm-build 0a0c83
const char *
rpm-build 0a0c83
group_name(gid_t gid, int numeric)
rpm-build 0a0c83
{
rpm-build 0a0c83
	struct group *group = numeric ? NULL : getgrgid(gid);
rpm-build 0a0c83
	static char gid_str[22];
rpm-build 0a0c83
	int ret;
rpm-build 0a0c83
rpm-build 0a0c83
	if (group != NULL)
rpm-build 0a0c83
		return group->gr_name;
rpm-build 0a0c83
	ret = snprintf(gid_str, sizeof(gid_str), "%ld", (long)gid);
rpm-build 0a0c83
	if (ret < 1 || (size_t)ret >= sizeof(gid_str))
rpm-build 0a0c83
		return "?";
rpm-build 0a0c83
	return gid_str;
rpm-build 0a0c83
}
rpm-build 0a0c83