[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: idcache
From: |
Jim Meyering |
Subject: |
Re: idcache |
Date: |
Fri, 17 Aug 2007 16:56:52 +0200 |
address@hidden wrote:
> is the header file for idcache.c just missing?
Yep. Known ugliness. Just waiting for you to mention it :-)
That whole module isn't very pretty. And it makes any application
that uses it (like ls) look like it has a leak.
Here's what I'll probably commit to address the missing-header part:
* modules/idcache (Files): Add lib/idcache.h
* lib/idcache.c: Include "idcache.h".
Don't include <sys/types.h>.
Add a FIXME comment.
Move file-scoped "static" declarations to the top.
* lib/idcache.h: New file. Include <sys/types.h> here, instead.
Index: modules/idcache
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/idcache,v
retrieving revision 1.10
diff -u -p -r1.10 idcache
--- modules/idcache 20 Nov 2006 10:54:06 -0000 1.10
+++ modules/idcache 17 Aug 2007 14:55:47 -0000
@@ -3,6 +3,7 @@ Username <--> uid and groupname <--> gid
Files:
lib/idcache.c
+lib/idcache.h
m4/idcache.m4
Depends-on:
Index: lib/idcache.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/idcache.c,v
retrieving revision 1.23
diff -u -p -r1.23 idcache.c
--- lib/idcache.c 20 Nov 2006 13:08:38 -0000 1.23
+++ lib/idcache.c 17 Aug 2007 14:55:47 -0000
@@ -1,6 +1,6 @@
/* idcache.c -- map user and group IDs, cached for speed
- Copyright (C) 1985, 1988, 1989, 1990, 1997, 1998, 2003, 2005, 2006
+ Copyright (C) 1985, 1988, 1989, 1990, 1997, 1998, 2003, 2005-2007
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
@@ -19,10 +19,10 @@
#include <config.h>
+#include "idcache.h"
#include <stddef.h>
#include <stdio.h>
#include <string.h>
-#include <sys/types.h>
#include <pwd.h>
#include <grp.h>
@@ -45,11 +45,24 @@ struct userid
char name[FLEXIBLE_ARRAY_MEMBER];
};
+/* FIXME: provide a function to free any malloc'd storage and reset lists,
+ so that an application can use code like this just before exiting:
+ #ifdef lint
+ idcache_clear ();
+ #endif
+*/
+
static struct userid *user_alist;
/* Each entry on list is a user name for which the first lookup failed. */
static struct userid *nouser_alist;
+/* Use the same struct as for userids. */
+static struct userid *group_alist;
+
+/* Each entry on list is a group name for which the first lookup failed. */
+static struct userid *nogroup_alist;
+
/* Translate UID to a login name, with cache, or NULL if unresolved. */
char *
@@ -132,12 +145,6 @@ getuidbyname (const char *user)
return NULL;
}
-/* Use the same struct as for userids. */
-static struct userid *group_alist;
-
-/* Each entry on list is a group name for which the first lookup failed. */
-static struct userid *nogroup_alist;
-
/* Translate GID to a group name, with cache, or NULL if unresolved. */
char *
Index: lib/idcache.h
===================================================================
RCS file: lib/idcache.h
diff -N lib/idcache.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lib/idcache.h 17 Aug 2007 14:55:47 -0000
@@ -0,0 +1,11 @@
+#ifndef IDCACHE_H
+# define IDCACHE_H 1
+
+# include <sys/types.h>
+
+extern char *getuser (uid_t uid);
+extern char *getgroup (gid_t gid);
+extern uid_t *getuidbyname (const char *user);
+extern gid_t *getgidbyname (const char *group);
+
+#endif
- idcache, sky, 2007/08/17
- Re: idcache,
Jim Meyering <=