aboutsummaryrefslogtreecommitdiff
path: root/libbb/my_getug.c
diff options
context:
space:
mode:
authorbug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277>2004-09-15 03:04:08 +0000
committerbug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277>2004-09-15 03:04:08 +0000
commit1f43cf7fc3562db5698a2a2e7146b8350d9a461f (patch)
treef34d5e6241ef8f0a1a95502128789b2edd2c1a71 /libbb/my_getug.c
parent0f69811499160f2c76951dd3ff50168b705826b1 (diff)
downloadbusybox-w32-1f43cf7fc3562db5698a2a2e7146b8350d9a461f.tar.gz
busybox-w32-1f43cf7fc3562db5698a2a2e7146b8350d9a461f.tar.bz2
busybox-w32-1f43cf7fc3562db5698a2a2e7146b8350d9a461f.zip
Tito writes,
"This patch fixes all the bugs in id previously spotted by vodz and me. The binary size increased a bit, but now it should work as expected." git-svn-id: svn://busybox.net/trunk/busybox@9256 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to '')
-rw-r--r--libbb/my_getug.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/libbb/my_getug.c b/libbb/my_getug.c
new file mode 100644
index 000000000..894dc5fdd
--- /dev/null
+++ b/libbb/my_getug.c
@@ -0,0 +1,64 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Utility routines.
4 *
5 * Copyright (C) 2004 by Tito Ragusa <farmatito@tiscali.it>
6 *
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.
11 *
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.
16 *
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
20 */
21
22 /*
23 *
24 * if bufsize is > 0 char *idname can not be set to NULL.
25 * On success idname is written on static allocated buffer
26 * (and a pointer to it is returned).
27 * On failure uid or gid as string is written to static allocated buffer
28 * and NULL is returned.
29 * if bufsize is = 0 char *idname can be set to NULL.
30 * On success idname is returned.
31 * On failure NULL is returned.
32 * if bufsize is < 0 char *idname can be set to NULL.
33 * On success idname is returned.
34 * On failure an error message is printed and the program exits.
35 */
36
37#include <stdio.h>
38#include <assert.h>
39#include "libbb.h"
40
41
42/* internal function for my_getpwuid and my_getgrgid */
43char * my_getug(char *buffer, char *idname, long id, int bufsize, char prefix)
44{
45 if(bufsize > 0 ) {
46 assert(buffer!=NULL);
47 if(idname) {
48 return safe_strncpy(buffer, idname, bufsize);
49 }
50 snprintf(buffer, bufsize, "%ld", id);
51 } else if(bufsize < 0 && !idname) {
52 bb_error_msg_and_die("unknown %cid %ld", prefix, id);
53 }
54 return idname;
55}
56
57/* END CODE */
58/*
59Local Variables:
60c-file-style: "linux"
61c-basic-offset: 4
62tab-width: 4
63End:
64*/