1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
3 * ALSA SEQ < - > JACK MIDI bridge
5 * Copyright (c) 2008,2009 Nedko Arnaudov <nedko@arnaudov.name>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #define DEFAULT_XDG_LOG "/.log"
31 #define DEFAULT_XDG_CONF "/.config"
32 #define A2J_XDG_SUBDIR "/a2j"
33 #define A2J_XDG_LOG "/a2j.log"
34 #define A2J_XDG_CONF "/a2j.conf"
36 char * g_a2j_log_path
= NULL
;
37 char * g_a2j_conf_path
= NULL
;
48 str1_len
= strlen(str1
);
49 str2_len
= strlen(str2
);
51 str
= malloc(str1_len
+ str2_len
+ 1);
57 memcpy(str
, str1
, str1_len
);
58 memcpy(str
+ str1_len
, str2
, str2_len
);
59 str
[str1_len
+ str2_len
] = 0;
70 if (stat(dirname
, &st
) != 0)
74 a2j_info("Directory \"%s\" does not exist. Creating...", dirname
);
75 if (mkdir(dirname
, mode
) != 0)
77 a2j_error("Failed to create \"%s\" directory: %d (%s)", dirname
, errno
, strerror(errno
));
83 a2j_error("Failed to stat \"%s\": %d (%s)", dirname
, errno
, strerror(errno
));
89 if (!S_ISDIR(st
.st_mode
))
91 a2j_error("\"%s\" exists but is not directory.", dirname
);
101 const char * home_dir
,
102 const char * purpose_subdir
,
111 dir1
= catdup(home_dir
, purpose_subdir
);
114 a2j_error("Out of memory");
118 dir2
= catdup(dir1
, A2J_XDG_SUBDIR
);
121 a2j_error("Out of memory");
125 if (!ensure_dir_exist(dir1
, 0700))
130 if (!ensure_dir_exist(dir2
, 0700))
135 filepath
= catdup(dir2
, file
);
136 if (filepath
== NULL
)
138 a2j_error("Out of memory");
154 const char * home_dir
;
156 home_dir
= getenv("HOME");
157 if (home_dir
== NULL
)
159 a2j_error("Environment variable HOME not set");
163 g_a2j_log_path
= a2j_path_init(home_dir
, DEFAULT_XDG_LOG
, A2J_XDG_LOG
);
164 if (g_a2j_log_path
== NULL
)
169 g_a2j_conf_path
= a2j_path_init(home_dir
, DEFAULT_XDG_CONF
, A2J_XDG_CONF
);
170 if (g_a2j_conf_path
== NULL
)
178 free(g_a2j_log_path
);
185 a2j_paths_uninit(void)
187 if (g_a2j_conf_path
!= NULL
)
189 free(g_a2j_conf_path
);
192 if (g_a2j_log_path
!= NULL
)
194 free(g_a2j_log_path
);