File: util.c

package info (click to toggle)
esound 0.2.35-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,828 kB
  • ctags: 808
  • sloc: ansic: 10,220; sh: 8,620; makefile: 237; csh: 86
file content (60 lines) | stat: -rw-r--r-- 1,060 bytes parent folder | download
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
60
#include "config.h"
#include "esd.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

/* Run-time check for IPv6 support */
int 
have_ipv6() {
#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) 
{
	char *audiodev;
	static char *dirname = NULL;

	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);
	}

	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;
}