-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutil.c
59 lines (52 loc) · 1.18 KB
/
util.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "config.h"
#include "esd.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
/* Run-time check for IPv6 support */
int
have_ipv6(void) {
#if defined ENABLE_IPV6
int s;
s = socket(AF_INET6, SOCK_STREAM, 0);
if(s != -1) {
close(s);
return (1);
}
#endif
return (0);
}
const char*
esd_get_socket_dirname (void)
{
const char *audiodev = NULL;
static char *dirname = NULL;
if (dirname == NULL) {
if ((audiodev = getenv("AUDIODEV"))) {
char *newdev = strrchr(audiodev, '/');
if (newdev != NULL) {
audiodev = newdev++;
}
} else
audiodev = "";
dirname = malloc(strlen(audiodev) + 40);
sprintf (dirname, "/tmp/.esd%s-%i", audiodev, getuid());
}
return dirname;
}
const char*
esd_get_socket_name (void)
{
const char *dirname;
static char *name = NULL;
if (name == NULL) {
dirname = esd_get_socket_dirname();
name = malloc(strlen(dirname) + sizeof("/socket"));
strcpy(name, dirname);
strcat(name, "/socket");
}
return name;
}