From 50d1c4c74552c97464536a17a45aba2f12facbec Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Mon, 12 Nov 2007 08:07:00 +0100 Subject: [PATCH] Fake implementions of getpwuid(), getuid(), and getpwnam(). getpwuid() is kept as simple as possible so that no errors are generated. Since the information that it returns is not very useful, users are still required to set up user.name and user.email configuration. All uses of getpwuid() are like getpwuid(getuid()), hence, the return value of getpwuid() is irrelevant. getpwnam() is only used to resolve '~' and '~username' paths, which is an idiom not known on Windows, hence, we don't implement it, either. Signed-off-by: Johannes Sixt --- compat/mingw.c | 14 ++++++++++++++ git-compat-util.h | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/compat/mingw.c b/compat/mingw.c index 4e1003442d..152915fd21 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -620,3 +620,17 @@ int mingw_vsnprintf(char *buf, size_t size, const char *fmt, va_list args) } while (len < 0); return len; } + +struct passwd *mingw_getpwuid(int uid) +{ + static char user_name[100]; + static struct passwd p; + + DWORD len = sizeof(user_name); + if (!GetUserName(user_name, &len)) + return NULL; + p.pw_name = user_name; + p.pw_gecos = "unknown"; + p.pw_dir = NULL; + return &p; +} diff --git a/git-compat-util.h b/git-compat-util.h index 66c4fb37a5..79ce4e0c2f 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -527,6 +527,16 @@ int git_fstat(int fd, struct stat *buf); int mingw_vsnprintf(char *buf, size_t size, const char *fmt, va_list args); #define vsnprintf mingw_vsnprintf +struct passwd { + char *pw_name; + char *pw_gecos; + char *pw_dir; +}; +struct passwd *mingw_getpwuid(int uid); +#define getpwuid mingw_getpwuid +static inline int getuid() { return 1; } +static inline struct passwd *getpwnam(const char *name) { return NULL; } + #endif /* __MINGW32__ */ #endif