]>
git.saurik.com Git - apple/libinfo.git/blob - util.subproj/pwcache.c
f0a4eec5071c5e286e5a36faee181b2d0403b361
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
27 * Copyright (c) 1989, 1993
28 * The Regents of the University of California. All rights reserved.
30 * The NEXTSTEP Software License Agreement specifies the terms
31 * and conditions for redistribution.
33 * @(#)pwcache.c 8.1 (Berkeley) 6/4/93
37 #include <sys/types.h>
44 #define NCACHE 64 /* power of 2 */
45 #define MASK NCACHE - 1 /* bits to store with */
48 user_from_uid(uid
, nouser
)
52 static struct ncache
{
54 char name
[UT_NAMESIZE
+ 1];
57 static char nbuf
[15]; /* 32 bits == 10 digits */
58 register struct passwd
*pw
;
59 register struct ncache
*cp
;
61 cp
= c_uid
+ (uid
& MASK
);
62 if (cp
->uid
!= uid
|| !*cp
->name
) {
67 if ((pw
= getpwuid(uid
)) == NULL
) {
70 (void)snprintf(nbuf
, sizeof(nbuf
), "%u", uid
);
74 (void)strncpy(cp
->name
, pw
->pw_name
, UT_NAMESIZE
);
75 cp
->name
[UT_NAMESIZE
] = '\0';
81 group_from_gid(gid
, nogroup
)
85 static struct ncache
{
87 char name
[UT_NAMESIZE
+ 1];
90 static char nbuf
[15]; /* 32 bits == 10 digits */
94 cp
= c_gid
+ (gid
& MASK
);
95 if (cp
->gid
!= gid
|| !*cp
->name
) {
100 if ((gr
= getgrgid(gid
)) == NULL
) {
103 (void)snprintf(nbuf
, sizeof(nbuf
), "%u", gid
);
107 (void)strncpy(cp
->name
, gr
->gr_name
, UT_NAMESIZE
);
108 cp
->name
[UT_NAMESIZE
] = '\0';