openbsd-ports/audio/esound/patches/patch-util_c
martynas 6b4cd39bde revert to 0.2.34; this is known to cause problems for devices with
48kHz sampling rate, originally reported by Gareth <garf at
loveandnature dot co dot za>
testing and patches from jakemsr@, aanriot@ and Tim van der Molen
<tbvdm.lists at xs4all dot nl>
ok naddy@, jakemsr@, simon@, jasper@
2007-08-11 17:29:36 +00:00

71 lines
1.7 KiB
Plaintext

$OpenBSD: patch-util_c,v 1.4 2007/08/11 17:29:36 martynas Exp $
--- util.c.orig Mon Mar 1 12:06:58 2004
+++ util.c Thu Jun 24 20:15:35 2004
@@ -1,5 +1,8 @@
#include "config.h"
#include "esd.h"
+#include <limits.h>
+#include <pwd.h>
+#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.h>
@@ -23,38 +26,31 @@ have_ipv6() {
const char*
esd_get_socket_dirname (void)
{
- char *audiodev;
- static char *dirname = NULL;
+ static char *sockdir = NULL, sockdirbuf[PATH_MAX];
+ struct passwd *pw;
- if (dirname == NULL) {
- if (!(audiodev = getenv("AUDIODEV"))) {
- audiodev = "";
- } else {
- char *newdev = strrchr(audiodev, '/');
- if (newdev != NULL) {
- audiodev = newdev++;
- }
- }
- dirname = malloc(strlen(audiodev) + sizeof("/tmp/.esd"));
- strcpy(dirname, "/tmp/.esd");
- strcat(dirname, audiodev);
+ if (sockdir != NULL)
+ return (sockdir);
+ pw = getpwuid(getuid());
+ if (pw == NULL || pw->pw_dir == NULL) {
+ fprintf(stderr, "esd: could not find home directory\n");
+ exit(1);
}
-
- return dirname;
+ snprintf(sockdirbuf, sizeof(sockdirbuf), "%s/.esd", pw->pw_dir);
+ endpwent();
+ sockdir = sockdirbuf;
+ return (sockdir);
}
const char*
esd_get_socket_name (void)
{
- const char *dirname;
- static char *name = NULL;
+ static char *sockname = NULL, socknamebuf[PATH_MAX];
- if (name == NULL) {
- dirname = esd_get_socket_dirname();
- name = malloc(strlen(dirname) + sizeof("/socket"));
- strcpy(name, dirname);
- strcat(name, "/socket");
- }
-
- return name;
+ if (sockname != NULL)
+ return (sockname);
+ snprintf(socknamebuf, sizeof(socknamebuf), "%s/socket",
+ esd_get_socket_dirname());
+ sockname = socknamebuf;
+ return (sockname);
}