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 <johannes.sixt@telecom.at>
This commit is contained in:
Johannes Sixt
2007-11-12 08:07:00 +01:00
parent 89e51c3105
commit 50d1c4c745
2 changed files with 24 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -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