ident: add NO_GECOS_IN_PWENT for systems without pw_gecos in struct passwd

Allow NO_GECOS_IN_PWENT to be defined in the Makefile for platforms that lack the pw_gecos field in their "struct passwd", in which case the uppercased user name is used instead via the standard '&' replacement mechanism. Signed-off-by: Rafael Gieschke <rafael@gieschke.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Rafael Gieschke committed May 19, 2011 at 13:37 UTC 590e081dea7c064056941bfae28b25ce956585f5
2 files changed +10 -1
Makefile
+3
@@ -59,6 +59,9 @@ all::
59 #
60 # Define NO_MKSTEMPS if you don't have mkstemps in the C library.
61 #
62 +# Define NO_GECOS_IN_PWENT if you don't have pw_gecos in struct passwd
63 +# in the C library.
64 +#
65 # Define NO_LIBGEN_H if you don't have libgen.h.
66 #
67 # Define NEEDS_LIBGEN if your libgen needs -lgen when linking
ident.c
+7 -1
@@ -9,6 +9,12 @@
9
10 static char git_default_date[50];
11
12 +#ifdef NO_GECOS_IN_PWENT
13 +#define get_gecos(ignored) "&"
14 +#else
15 +#define get_gecos(struct_passwd) ((struct_passwd)->pw_gecos)
16 +#endif
17 +
18 static void copy_gecos(const struct passwd *w, char *name, size_t sz)
19 {
20 char *src, *dst;
@@ -20,7 +26,7 @@ static void copy_gecos(const struct passwd *w, char *name, size_t sz)
26 * with commas. Also & stands for capitalized form of the login name.
27 */
28
23 - for (len = 0, dst = name, src = w->pw_gecos; len < sz; src++) {
29 + for (len = 0, dst = name, src = get_gecos(w); len < sz; src++) {
30 int ch = *src;
31 if (ch != '&') {
32 *dst++ = ch;