/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#pragma prototyped22/*23* Glenn Fowler24* AT&T Bell Laboratories25*26* cached gid number -> name27*/2829#if defined(__STDPP__directive) && defined(__STDPP__hide)30__STDPP__directive pragma pp:hide getgrgid31#else32#define getgrgid ______getgrgid33#endif3435#include <ast.h>36#include <cdt.h>37#include <grp.h>3839#if defined(__STDPP__directive) && defined(__STDPP__hide)40__STDPP__directive pragma pp:nohide getgrgid41#else42#undef getgrgid43#endif4445extern struct group* getgrgid(gid_t);4647typedef struct Id_s48{49Dtlink_t link;50int id;51char name[1];52} Id_t;5354/*55* return gid name given gid number56*/5758char*59fmtgid(int gid)60{61register Id_t* ip;62register char* name;63register struct group* gr;64int z;6566static Dt_t* dict;67static Dtdisc_t disc;6869if (!dict)70{71disc.key = offsetof(Id_t, id);72disc.size = sizeof(int);73dict = dtopen(&disc, Dtset);74}75else if (ip = (Id_t*)dtmatch(dict, &gid))76return ip->name;77if (gr = getgrgid(gid))78{79name = gr->gr_name;80#if _WINIX81if (streq(name, "Administrators"))82name = "sys";83#endif84}85else if (gid == 0)86name = "sys";87else88{89name = fmtbuf(z = sizeof(gid) * 3 + 1);90sfsprintf(name, z, "%I*d", sizeof(gid), gid);91}92if (dict && (ip = newof(0, Id_t, 1, strlen(name))))93{94ip->id = gid;95strcpy(ip->name, name);96dtinsert(dict, ip);97return ip->name;98}99return name;100}101102103