aboutsummaryrefslogtreecommitdiff
path: root/include/synthpod_common.h
blob: d365478ea4563e6e4fe98c80dbe98d617143215e (plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 * Copyright (c) 2015-2016 Hanspeter Portner (dev@open-music-kontrollers.ch)
 *
 * This is free software: you can redistribute it and/or modify
 * it under the terms of the Artistic License 2.0 as published by
 * The Perl Foundation.
 *
 * This source is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * Artistic License 2.0 for more details.
 *
 * You should have received a copy of the Artistic License 2.0
 * along the source as a COPYING file. If not, obtain it from
 * http://www.perlfoundation.org/artistic_license_2_0.
 */

#ifndef _SYNTHPOD_COMMON_H
#define _SYNTHPOD_COMMON_H

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <err.h>
#include <errno.h>
#include <string.h>
#include <ftw.h>

#define SYNTHPOD_PREFIX					"http://open-music-kontrollers.ch/lv2/synthpod#"

#define SYNTHPOD_STEREO_URI			SYNTHPOD_PREFIX"stereo"

#define SYNTHPOD_COMMON_NK_URI	SYNTHPOD_PREFIX"common_4_nk"
#define SYNTHPOD_ROOT_NK_URI	  SYNTHPOD_PREFIX"root_4_nk"

#define SYNTHPOD_COMMON_D2TK_URI	SYNTHPOD_PREFIX"common_5_d2tk"
#define SYNTHPOD_ROOT_D2TK_URI	  SYNTHPOD_PREFIX"root_5_d2tk"

#ifdef _WIN32
#	define mlock(...)
#	define munlock(...)
#else
#	include <sys/mman.h> // mlock
#endif

#include <xpress.lv2/xpress.h>

#define __realtime __attribute__((annotate("realtime")))
#define __non_realtime __attribute__((annotate("non-realtime")))

static inline int
mkpath(char *path)
{
	struct stat sb;
	char *slash;
	bool done = false;

	slash = path;

	while(!done)
	{
		slash += strspn(slash, "/");
		slash += strcspn(slash, "/");

		done = *slash == '\0';
		*slash = '\0';

		if(stat(path, &sb))
		{
			if(  (errno != ENOENT)
				|| (mkdir(path, 0777) && (errno != EEXIST)) )
			{
				return -1;
			}
		}
		else if(!S_ISDIR(sb.st_mode))
		{
			return -1;
		}

		*slash = '/';
	}

	return 0;
}

static inline int
mkpath_const(const char *path)
{
	char *dup = strdup(path);
	if(!dup)
		return -1;

	const int ret = mkpath(dup);
	free(dup);
	return ret;
}

static inline int
_unlink_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
{
	return remove(fpath);
}

static inline int
rmrf_const(const char *path)
{
	return nftw(path, _unlink_cb, 64, FTW_DEPTH | FTW_PHYS);
}

#endif // _SYNTHPOD_COMMON_H