summaryrefslogtreecommitdiffstats
path: root/polyp/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-11-01 23:37:36 +0000
committerLennart Poettering <lennart@poettering.net>2004-11-01 23:37:36 +0000
commitcd3ba7d0f745f8063cc018aeca320939ef3cd637 (patch)
tree381934f8a85391e6125fe1f7b9cd5e4217c5ec5e /polyp/util.c
parent899788b4c5e23af9dabfb98c5f864c2f933804f4 (diff)
Apply Joe Marcus Clarke's FreeBSD patches
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@269 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'polyp/util.c')
-rw-r--r--polyp/util.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/polyp/util.c b/polyp/util.c
index 9697a1eb..b138266b 100644
--- a/polyp/util.c
+++ b/polyp/util.c
@@ -209,7 +209,13 @@ char *pa_get_user_name(char *s, size_t l) {
if (!(p = getenv("LOGNAME")))
if (!(p = getenv("USERNAME"))) {
+#ifdef HAVE_GETPWUID_R
if (getpwuid_r(getuid(), &pw, buf, sizeof(buf), &r) != 0 || !r) {
+#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) {
+#endif
snprintf(s, l, "%lu", (unsigned long) getuid());
return s;
}
@@ -445,11 +451,17 @@ int pa_parse_resample_method(const char *string) {
static int is_group(gid_t gid, const char *name) {
struct group group, *result = NULL;
- long n = sysconf(_SC_GETGR_R_SIZE_MAX);
+ long n;
void *data;
int r = -1;
-
- assert(n > 0);
+
+#ifdef HAVE_GETGRGID_R
+#ifdef _SC_GETGR_R_SIZE_MAX
+ n = sysconf(_SC_GETGR_R_SIZE_MAX);
+#else
+ n = -1;
+#endif
+ if (n < 0) n = 512;
data = pa_xmalloc(n);
if (getgrgid_r(gid, &group, data, n, &result) < 0 || !result) {
@@ -462,6 +474,18 @@ static int is_group(gid_t gid, const char *name) {
finish:
pa_xfree(data);
+#else
+ /* XXX Not thread-safe, but needed on OSes (e.g. FreeBSD 4.X) that do not
+ * support getgrgid_r. */
+ if ((result = getgrgid(gid)) == NULL) {
+ pa_log(__FILE__ ": getgrgid(%u) failed: %s\n", gid, strerror(errno));
+ goto finish;
+ }
+
+ r = strcmp(name, result->gr_name) == 0;
+
+finish:
+#endif
return r;
}