]>
git.saurik.com Git - apple/libinfo.git/blob - util.subproj/pwcache.c
ce31e7a9fb3a4d573fe4536403ad50b0b4c4ee10
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) 1980, 1988, 1993
28 * The Regents of the University of California. All rights reserved.
30 * @(#)fstab.c 8.1 (Berkeley) 6/4/93
33 #include <sys/types.h>
43 #define NCACHE 64 /* power of 2 */
44 #define MASK (NCACHE - 1) /* bits to store with */
47 user_from_uid(uid
, nouser
)
51 static struct ncache
{
53 char name
[_UTX_USERSIZE
+ 1];
56 static char nbuf
[15]; /* 32 bits == 10 digits */
57 register struct passwd
*pw
;
58 register struct ncache
**cp
;
60 cp
= &c_uid
[uid
& MASK
];
61 if (*cp
== NULL
|| (*cp
)->uid
!= uid
|| !*(*cp
)->name
) {
66 if ((pw
= getpwuid(uid
)) == NULL
) {
70 (void)snprintf(nbuf
, sizeof(nbuf
), "%u", uid
);
74 *cp
= malloc(sizeof(struct ncache
));
79 (void)strncpy((*cp
)->name
, pw
->pw_name
, _UTX_USERSIZE
);
80 (*cp
)->name
[_UTX_USERSIZE
] = '\0';
86 group_from_gid(gid
, nogroup
)
90 static struct ncache
{
92 char name
[_UTX_USERSIZE
+ 1];
95 static char nbuf
[15]; /* 32 bits == 10 digits */
97 struct ncache
**cp
= NULL
;
99 cp
= &c_gid
[gid
& MASK
];
100 if (*cp
== NULL
|| (*cp
)->gid
!= gid
|| !*(*cp
)->name
) {
105 if ((gr
= getgrgid(gid
)) == NULL
) {
109 (void)snprintf(nbuf
, sizeof(nbuf
), "%u", gid
);
113 *cp
= malloc(sizeof(struct ncache
));
118 (void)strncpy((*cp
)->name
, gr
->gr_name
, _UTX_USERSIZE
);
119 (*cp
)->name
[_UTX_USERSIZE
] = '\0';
121 return ((*cp
)->name
);