File: util.c

package info (click to toggle)
esound 0.2.41-10
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 3,404 kB
  • sloc: ansic: 10,607; sh: 9,254; makefile: 186; csh: 86
file content (59 lines) | stat: -rw-r--r-- 1,213 bytes parent folder | download | duplicates (3)
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;
}