提交 590e081d 编写于 作者: R Rafael Gieschke 提交者: Junio C Hamano

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: NRafael Gieschke <rafael@gieschke.de>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 c0336ff2
...@@ -59,6 +59,9 @@ all:: ...@@ -59,6 +59,9 @@ all::
# #
# Define NO_MKSTEMPS if you don't have mkstemps in the C library. # Define NO_MKSTEMPS if you don't have mkstemps in the C library.
# #
# Define NO_GECOS_IN_PWENT if you don't have pw_gecos in struct passwd
# in the C library.
#
# Define NO_LIBGEN_H if you don't have libgen.h. # Define NO_LIBGEN_H if you don't have libgen.h.
# #
# Define NEEDS_LIBGEN if your libgen needs -lgen when linking # Define NEEDS_LIBGEN if your libgen needs -lgen when linking
......
...@@ -9,6 +9,12 @@ ...@@ -9,6 +9,12 @@
static char git_default_date[50]; static char git_default_date[50];
#ifdef NO_GECOS_IN_PWENT
#define get_gecos(ignored) "&"
#else
#define get_gecos(struct_passwd) ((struct_passwd)->pw_gecos)
#endif
static void copy_gecos(const struct passwd *w, char *name, size_t sz) static void copy_gecos(const struct passwd *w, char *name, size_t sz)
{ {
char *src, *dst; char *src, *dst;
...@@ -20,7 +26,7 @@ static void copy_gecos(const struct passwd *w, char *name, size_t sz) ...@@ -20,7 +26,7 @@ static void copy_gecos(const struct passwd *w, char *name, size_t sz)
* with commas. Also & stands for capitalized form of the login name. * with commas. Also & stands for capitalized form of the login name.
*/ */
for (len = 0, dst = name, src = w->pw_gecos; len < sz; src++) { for (len = 0, dst = name, src = get_gecos(w); len < sz; src++) {
int ch = *src; int ch = *src;
if (ch != '&') { if (ch != '&') {
*dst++ = ch; *dst++ = ch;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册