#include "platform.h"
-#if !defined(PLATFORM_WIN32)
+#if defined(PLATFORM_UNIX)
#include <pwd.h>
#include <sys/param.h>
#endif
}
#endif
+#if defined(PLATFORM_UNIX)
+static struct passwd *getPasswdEntry(void)
+{
+ return getpwuid(getuid());
+}
+
+char *getUnixLoginName(void)
+{
+ struct passwd *pwd = getPasswdEntry();
+
+ if (pwd != NULL && strlen(pwd->pw_name) != 0)
+ return pwd->pw_name;
+
+ return NULL;
+}
+
+char *getUnixRealName(void)
+{
+ struct passwd *pwd = getPasswdEntry();
+
+ if (pwd != NULL && strlen(pwd->pw_gecos) != 0)
+ return pwd->pw_gecos;
+
+ return NULL;
+}
+
+char *getUnixHomeDir(void)
+{
+ struct passwd *pwd = getPasswdEntry();
+
+ if (pwd != NULL && strlen(pwd->pw_dir) != 0)
+ return pwd->pw_dir;
+
+ return NULL;
+}
+#endif
+
char *getLoginName(void)
{
static char *login_name = NULL;
if (login_name == NULL)
{
unsigned long buffer_size = MAX_USERNAME_LEN + 1;
+
login_name = checked_malloc(buffer_size);
if (GetUserName(login_name, &buffer_size) == 0)
#elif defined(PLATFORM_UNIX) && !defined(PLATFORM_ANDROID)
if (login_name == NULL)
{
- struct passwd *pwd;
+ char *name = getUnixLoginName();
- if ((pwd = getpwuid(getuid())) == NULL)
- login_name = ANONYMOUS_NAME;
+ if (name != NULL)
+ login_name = getStringCopy(name);
else
- login_name = getStringCopy(pwd->pw_name);
+ login_name = ANONYMOUS_NAME;
}
#else
login_name = ANONYMOUS_NAME;
#elif defined(PLATFORM_UNIX) && !defined(PLATFORM_ANDROID)
if (real_name == NULL)
{
- struct passwd *pwd;
+ char *name = getUnixRealName();
- if ((pwd = getpwuid(getuid())) != NULL && strlen(pwd->pw_gecos) != 0)
- real_name = get_corrected_real_name(pwd->pw_gecos);
+ if (name != NULL)
+ real_name = get_corrected_real_name(name);
else
real_name = ANONYMOUS_NAME;
}
unsigned int init_random_number(int, int);
unsigned int get_random_number(int, int);
+#if defined(PLATFORM_UNIX)
+char *getUnixLoginName(void);
+char *getUnixRealName(void);
+char *getUnixHomeDir(void);
+#endif
+
char *getLoginName(void);
char *getRealName(void);
#include "platform.h"
-#if !defined(PLATFORM_WIN32)
-#include <pwd.h>
-#include <sys/param.h>
-#endif
-
#include "setup.h"
#include "joystick.h"
#include "text.h"
{
if ((dir = getenv("HOME")) == NULL)
{
- struct passwd *pwd;
+ dir = getUnixHomeDir();
- if ((pwd = getpwuid(getuid())) != NULL)
- dir = getStringCopy(pwd->pw_dir);
+ if (dir != NULL)
+ dir = getStringCopy(dir);
else
dir = ".";
}