-/* $Id$ */
-
/***
This file is part of PulseAudio.
#include <sys/prctl.h>
#endif
+#include <pulse/xmalloc.h>
#include <pulsecore/winsock.h>
#include <pulsecore/core-error.h>
#include <pulsecore/log.h>
#include "util.h"
char *pa_get_user_name(char *s, size_t l) {
- char *p;
+ const char *p;
char buf[1024];
#ifdef HAVE_PWD_H
pa_assert(s);
pa_assert(l > 0);
- if (!(p = getenv("USER")) && !(p = getenv("LOGNAME")) && !(p = getenv("USERNAME"))) {
+ if (!(p = (getuid() == 0 ? "root" : NULL)) &&
+ !(p = getenv("USER")) &&
+ !(p = getenv("LOGNAME")) &&
+ !(p = getenv("USERNAME"))) {
#ifdef HAVE_PWD_H
#ifdef HAVE_GETPWUID_R
#elif defined(OS_IS_WIN32) /* HAVE_PWD_H */
DWORD size = sizeof(buf);
- if (!GetUserName(buf, &size))
+ if (!GetUserName(buf, &size)) {
+ errno = ENOENT;
return NULL;
+ }
p = buf;
#else /* HAVE_PWD_H */
+
return NULL;
#endif /* HAVE_PWD_H */
}
pa_assert(s);
pa_assert(l > 0);
- if (gethostname(s, l) < 0) {
- pa_log("gethostname(): %s", pa_cstrerror(errno));
+ if (gethostname(s, l) < 0)
return NULL;
- }
s[l-1] = 0;
return s;
return pa_strlcpy(s, e, l);
#ifdef HAVE_PWD_H
+
+ errno = 0;
#ifdef HAVE_GETPWUID_R
if (getpwuid_r(getuid(), &pw, buf, sizeof(buf), &r) != 0 || !r) {
- pa_log("getpwuid_r() failed");
#else
/* XXX Not thread-safe, but needed on OSes (e.g. FreeBSD 4.X)
* that do not support getpwuid_r. */
if ((r = getpwuid(getuid())) == NULL) {
- pa_log("getpwuid_r() failed");
#endif
+ if (!errno)
+ errno = ENOENT;
+
return NULL;
}
return pa_strlcpy(s, r->pw_dir, l);
#else /* HAVE_PWD_H */
+
+ errno = ENOENT;
return NULL;
#endif
}
#ifdef __linux__
{
- int i;
- char path[PATH_MAX];
+ char *rp;
/* This works on Linux only */
- if ((i = readlink("/proc/self/exe", path, sizeof(path)-1)) >= 0) {
- path[i] = 0;
- return pa_strlcpy(s, pa_path_get_filename(path), l);
+ if ((rp = pa_readlink("/proc/self/exe"))) {
+ pa_strlcpy(s, pa_path_get_filename(rp), l);
+ pa_xfree(rp);
+ return s;
}
}
}
#endif
+ errno = ENOENT;
return NULL;
}
#elif defined(HAVE_NANOSLEEP)
struct timespec ts;
- ts.tv_sec = t/1000;
- ts.tv_nsec = (t % 1000) * 1000000;
+ ts.tv_sec = (time_t) (t/1000UL);
+ ts.tv_nsec = (long) ((t % 1000UL) * 1000000UL);
return nanosleep(&ts, NULL);
#else