1 /* vi: set sw=4 ts=4: */
5 * Copyright (C) 2004 by Tito Ragusa <farmatito@tiscali.it>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * if bufsize is > 0 char *buffer can not be set to NULL.
25 * If idname is not NULL it is written on the static allocated buffer
26 * (and a pointer to it is returned).
27 * if idname is NULL, id as string is written to the static allocated buffer
28 * and NULL is returned.
29 * if bufsize is = 0 char *buffer can be set to NULL.
30 * If idname exists a pointer to it is returned,
31 * else NULL is returned.
32 * if bufsize is < 0 char *buffer can be set to NULL.
33 * If idname exists a pointer to it is returned,
34 * else an error message is printed and the program exits.
42 /* internal function for my_getpwuid and my_getgrgid */
43 char * my_getug(char *buffer, char *idname, long id, int bufsize, char prefix)
48 return safe_strncpy(buffer, idname, bufsize);
50 snprintf(buffer, bufsize, "%ld", id);
51 } else if(bufsize < 0 && !idname) {
52 bb_error_msg_and_die("unknown %cid %ld", prefix, id);