Skip to content

Commit 590e081

Browse files
rafaelgieschkegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c0336ff commit 590e081

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ all::
5959
#
6060
# Define NO_MKSTEMPS if you don't have mkstemps in the C library.
6161
#
62+
# Define NO_GECOS_IN_PWENT if you don't have pw_gecos in struct passwd
63+
# in the C library.
64+
#
6265
# Define NO_LIBGEN_H if you don't have libgen.h.
6366
#
6467
# Define NEEDS_LIBGEN if your libgen needs -lgen when linking

ident.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99

1010
static char git_default_date[50];
1111

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+
1218
static void copy_gecos(const struct passwd *w, char *name, size_t sz)
1319
{
1420
char *src, *dst;
@@ -20,7 +26,7 @@ static void copy_gecos(const struct passwd *w, char *name, size_t sz)
2026
* with commas. Also & stands for capitalized form of the login name.
2127
*/
2228

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++) {
2430
int ch = *src;
2531
if (ch != '&') {
2632
*dst++ = ch;

0 commit comments

Comments
 (0)