2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
28 * Copyright (c) 1989, 1993
29 * The Regents of the University of California. All rights reserved.
31 * The NEXTSTEP Software License Agreement specifies the terms
32 * and conditions for redistribution.
34 * @(#)pwcache.c 8.1 (Berkeley) 6/4/93
38 #include <sys/types.h>
47 #define NCACHE 64 /* power of 2 */
48 #define MASK (NCACHE - 1) /* bits to store with */
51 user_from_uid(uid
, nouser
)
55 static struct ncache
{
57 char name
[UT_NAMESIZE
+ 1];
60 static char nbuf
[15]; /* 32 bits == 10 digits */
61 register struct passwd
*pw
;
62 register struct ncache
**cp
;
64 cp
= &c_uid
[uid
& MASK
];
65 if (*cp
== NULL
|| (*cp
)->uid
!= uid
|| !*(*cp
)->name
) {
70 if ((pw
= getpwuid(uid
)) == NULL
) {
74 (void)snprintf(nbuf
, sizeof(nbuf
), "%u", uid
);
78 *cp
= malloc(sizeof(struct ncache
));
83 (void)strncpy((*cp
)->name
, pw
->pw_name
, UT_NAMESIZE
);
84 (*cp
)->name
[UT_NAMESIZE
] = '\0';
90 group_from_gid(gid
, nogroup
)
94 static struct ncache
{
96 char name
[UT_NAMESIZE
+ 1];
99 static char nbuf
[15]; /* 32 bits == 10 digits */
101 struct ncache
**cp
= NULL
;
103 cp
= &c_gid
[gid
& MASK
];
104 if (*cp
== NULL
|| (*cp
)->gid
!= gid
|| !*(*cp
)->name
) {
109 if ((gr
= getgrgid(gid
)) == NULL
) {
113 (void)snprintf(nbuf
, sizeof(nbuf
), "%u", gid
);
117 *cp
= malloc(sizeof(struct ncache
));
122 (void)strncpy((*cp
)->name
, gr
->gr_name
, UT_NAMESIZE
);
123 (*cp
)->name
[UT_NAMESIZE
] = '\0';
125 return ((*cp
)->name
);