2006-05-17 20:09:57 +00:00
|
|
|
#ifndef foocoreutilhfoo
|
|
|
|
|
#define foocoreutilhfoo
|
2004-06-23 23:17:30 +00:00
|
|
|
|
2004-07-16 19:56:36 +00:00
|
|
|
/***
|
2006-06-19 21:53:48 +00:00
|
|
|
This file is part of PulseAudio.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-02-13 15:35:19 +00:00
|
|
|
Copyright 2004-2006 Lennart Poettering
|
2007-02-14 12:13:49 +00:00
|
|
|
Copyright 2006-2007 Pierre Ossman <ossman@cendio.se> for Cendio AB
|
2007-02-13 15:35:19 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
2004-11-14 14:58:54 +00:00
|
|
|
it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2.1 of the
|
|
|
|
|
License, or (at your option) any later version.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
2004-07-16 19:56:36 +00:00
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2004-11-14 14:58:54 +00:00
|
|
|
Lesser General Public License for more details.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-14 14:58:54 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2006-06-19 21:53:48 +00:00
|
|
|
License along with PulseAudio; if not, write to the Free Software
|
2004-07-16 19:56:36 +00:00
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
|
USA.
|
|
|
|
|
***/
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
#include <sys/types.h>
|
2004-08-22 21:13:58 +00:00
|
|
|
#include <inttypes.h>
|
2004-09-05 00:03:16 +00:00
|
|
|
#include <stdarg.h>
|
2004-11-04 21:27:12 +00:00
|
|
|
#include <stdio.h>
|
2009-01-13 19:08:22 +02:00
|
|
|
#include <string.h>
|
2009-10-30 03:30:42 +01:00
|
|
|
#include <sys/socket.h>
|
2004-09-05 00:03:16 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
#ifdef HAVE_SYS_RESOURCE_H
|
|
|
|
|
#include <sys/resource.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <pulse/gccmacro.h>
|
2007-11-01 00:06:31 +00:00
|
|
|
#include <pulsecore/macro.h>
|
2004-06-23 23:17:30 +00:00
|
|
|
|
2008-10-04 00:10:43 +02:00
|
|
|
#ifndef PACKAGE
|
|
|
|
|
#error "Please include config.h before including this file!"
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-01-10 17:51:06 +00:00
|
|
|
struct timeval;
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
/* These resource limits are pretty new on Linux, let's define them
|
|
|
|
|
* here manually, in case the kernel is newer than the glibc */
|
|
|
|
|
#if !defined(RLIMIT_NICE) && defined(__linux__)
|
|
|
|
|
#define RLIMIT_NICE 13
|
|
|
|
|
#endif
|
|
|
|
|
#if !defined(RLIMIT_RTPRIO) && defined(__linux__)
|
|
|
|
|
#define RLIMIT_RTPRIO 14
|
|
|
|
|
#endif
|
|
|
|
|
#if !defined(RLIMIT_RTTIME) && defined(__linux__)
|
|
|
|
|
#define RLIMIT_RTTIME 15
|
|
|
|
|
#endif
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
void pa_make_fd_nonblock(int fd);
|
|
|
|
|
void pa_make_fd_cloexec(int fd);
|
2004-06-23 23:17:30 +00:00
|
|
|
|
2006-07-19 17:44:19 +00:00
|
|
|
int pa_make_secure_dir(const char* dir, mode_t m, uid_t uid, gid_t gid);
|
|
|
|
|
int pa_make_secure_parent_dir(const char *fn, mode_t, uid_t uid, gid_t gid);
|
2004-07-03 23:35:12 +00:00
|
|
|
|
2006-07-14 22:42:01 +00:00
|
|
|
ssize_t pa_read(int fd, void *buf, size_t count, int *type);
|
|
|
|
|
ssize_t pa_write(int fd, const void *buf, size_t count, int *type);
|
|
|
|
|
ssize_t pa_loop_read(int fd, void*data, size_t size, int *type);
|
|
|
|
|
ssize_t pa_loop_write(int fd, const void*data, size_t size, int *type);
|
2004-07-06 00:08:44 +00:00
|
|
|
|
2007-02-14 12:13:49 +00:00
|
|
|
int pa_close(int fd);
|
|
|
|
|
|
2004-09-15 13:03:25 +00:00
|
|
|
void pa_check_signal_is_blocked(int sig);
|
2004-07-07 00:22:46 +00:00
|
|
|
|
2004-09-05 00:03:16 +00:00
|
|
|
char *pa_sprintf_malloc(const char *format, ...) PA_GCC_PRINTF_ATTR(1,2);
|
|
|
|
|
char *pa_vsprintf_malloc(const char *format, va_list ap);
|
2004-07-10 20:56:38 +00:00
|
|
|
|
2004-11-04 18:57:31 +00:00
|
|
|
char *pa_strlcpy(char *b, const char *s, size_t l);
|
|
|
|
|
|
2006-04-22 20:05:01 +00:00
|
|
|
char *pa_parent_dir(const char *fn);
|
|
|
|
|
|
2007-11-01 02:58:26 +00:00
|
|
|
int pa_make_realtime(int rtprio);
|
|
|
|
|
int pa_raise_priority(int nice_level);
|
2004-09-01 00:23:51 +00:00
|
|
|
void pa_reset_priority(void);
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
int pa_parse_boolean(const char *s) PA_GCC_PURE;
|
2004-09-13 23:28:30 +00:00
|
|
|
|
2007-11-01 00:06:31 +00:00
|
|
|
static inline const char *pa_yes_no(pa_bool_t b) {
|
|
|
|
|
return b ? "yes" : "no";
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
static inline const char *pa_strnull(const char *x) {
|
|
|
|
|
return x ? x : "(null)";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline const char *pa_strempty(const char *x) {
|
|
|
|
|
return x ? x : "";
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-22 00:17:31 +01:00
|
|
|
static inline const char *pa_strna(const char *x) {
|
|
|
|
|
return x ? x : "n/a";
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-14 17:52:11 +00:00
|
|
|
char *pa_split(const char *c, const char*delimiters, const char **state);
|
2004-09-17 19:45:44 +00:00
|
|
|
char *pa_split_spaces(const char *c, const char **state);
|
2004-09-14 17:52:11 +00:00
|
|
|
|
2004-09-27 21:05:55 +00:00
|
|
|
char *pa_strip_nl(char *s);
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
const char *pa_sig2str(int sig) PA_GCC_PURE;
|
2004-09-15 13:03:25 +00:00
|
|
|
|
2006-02-24 17:14:23 +00:00
|
|
|
int pa_own_uid_in_group(const char *name, gid_t *gid);
|
|
|
|
|
int pa_uid_in_group(uid_t uid, const char *name);
|
2006-07-19 17:44:19 +00:00
|
|
|
gid_t pa_get_gid_of_group(const char *name);
|
2006-07-19 21:48:35 +00:00
|
|
|
int pa_check_in_group(gid_t g);
|
2004-09-23 15:47:11 +00:00
|
|
|
|
2004-09-28 22:47:48 +00:00
|
|
|
int pa_lock_fd(int fd, int b);
|
2004-09-27 15:40:18 +00:00
|
|
|
|
2004-09-28 22:47:48 +00:00
|
|
|
int pa_lock_lockfile(const char *fn);
|
2004-11-20 23:48:18 +00:00
|
|
|
int pa_unlock_lockfile(const char *fn, int fd);
|
2004-09-27 15:40:18 +00:00
|
|
|
|
2004-11-07 20:48:46 +00:00
|
|
|
char *pa_hexstr(const uint8_t* d, size_t dlength, char *s, size_t slength);
|
2004-11-08 23:48:19 +00:00
|
|
|
size_t pa_parsehex(const char *p, uint8_t *d, size_t dlength);
|
2004-11-07 20:48:46 +00:00
|
|
|
|
2008-05-21 22:39:40 +00:00
|
|
|
pa_bool_t pa_startswith(const char *s, const char *pfx) PA_GCC_PURE;
|
|
|
|
|
pa_bool_t pa_endswith(const char *s, const char *sfx) PA_GCC_PURE;
|
2004-11-11 21:18:33 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
FILE *pa_open_config_file(const char *global, const char *local, const char *env, char **result);
|
|
|
|
|
char* pa_find_config_file(const char *global, const char *local, const char *env);
|
|
|
|
|
|
|
|
|
|
char *pa_get_runtime_dir(void);
|
2008-05-21 22:39:40 +00:00
|
|
|
char *pa_get_state_dir(void);
|
2009-08-01 02:03:22 +02:00
|
|
|
char *pa_get_home_dir_malloc(void);
|
|
|
|
|
char *pa_get_binary_name_malloc(void);
|
2008-05-15 23:34:41 +00:00
|
|
|
char *pa_runtime_path(const char *fn);
|
2008-08-07 02:28:47 +02:00
|
|
|
char *pa_state_path(const char *fn, pa_bool_t prepend_machine_id);
|
2004-11-11 21:18:33 +00:00
|
|
|
|
2004-12-11 00:10:41 +00:00
|
|
|
int pa_atoi(const char *s, int32_t *ret_i);
|
|
|
|
|
int pa_atou(const char *s, uint32_t *ret_u);
|
2008-06-11 00:37:41 +00:00
|
|
|
int pa_atod(const char *s, double *ret_d);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-08-19 22:39:54 +02:00
|
|
|
size_t pa_snprintf(char *str, size_t size, const char *format, ...);
|
|
|
|
|
size_t pa_vsnprintf(char *str, size_t size, const char *format, va_list ap);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
char *pa_truncate_utf8(char *c, size_t l);
|
|
|
|
|
|
2009-02-18 21:57:16 +01:00
|
|
|
int pa_match(const char *expr, const char *v);
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
char *pa_getcwd(void);
|
|
|
|
|
char *pa_make_path_absolute(const char *p);
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_bool_t pa_is_path_absolute(const char *p);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
void *pa_will_need(const void *p, size_t l);
|
|
|
|
|
|
|
|
|
|
static inline int pa_is_power_of_two(unsigned n) {
|
|
|
|
|
return !(n & (n - 1));
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-29 01:13:50 +02:00
|
|
|
static inline unsigned pa_ulog2(unsigned n) {
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-08-29 01:13:50 +02:00
|
|
|
if (n <= 1)
|
|
|
|
|
return 0;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-08-29 01:13:50 +02:00
|
|
|
#if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
|
|
|
|
|
return 8U * (unsigned) sizeof(unsigned) - (unsigned) __builtin_clz(n) - 1;
|
|
|
|
|
#else
|
|
|
|
|
{
|
|
|
|
|
unsigned r = 0;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-08-29 01:13:50 +02:00
|
|
|
for (;;) {
|
|
|
|
|
n = n >> 1;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-08-29 01:13:50 +02:00
|
|
|
if (!n)
|
|
|
|
|
return r;
|
2008-05-15 23:34:41 +00:00
|
|
|
|
|
|
|
|
r++;
|
|
|
|
|
}
|
2008-08-29 01:13:50 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline unsigned pa_make_power_of_two(unsigned n) {
|
|
|
|
|
|
|
|
|
|
if (pa_is_power_of_two(n))
|
|
|
|
|
return n;
|
2008-05-15 23:34:41 +00:00
|
|
|
|
2008-08-29 01:13:50 +02:00
|
|
|
return 1U << (pa_ulog2(n) + 1);
|
2008-05-15 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
void pa_close_pipe(int fds[2]);
|
2004-12-11 00:10:41 +00:00
|
|
|
|
2007-10-29 15:31:24 +00:00
|
|
|
char *pa_readlink(const char *p);
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
int pa_close_all(int except_fd, ...);
|
|
|
|
|
int pa_close_allv(const int except_fds[]);
|
|
|
|
|
int pa_unblock_sigs(int except, ...);
|
|
|
|
|
int pa_unblock_sigsv(const int except[]);
|
|
|
|
|
int pa_reset_sigs(int except, ...);
|
|
|
|
|
int pa_reset_sigsv(const int except[]);
|
|
|
|
|
|
|
|
|
|
void pa_set_env(const char *key, const char *value);
|
2009-09-02 00:34:27 +02:00
|
|
|
void pa_set_env_and_record(const char *key, const char *value);
|
|
|
|
|
void pa_unset_env_recorded(void);
|
2008-05-15 23:34:41 +00:00
|
|
|
|
2008-05-21 22:39:40 +00:00
|
|
|
pa_bool_t pa_in_system_mode(void);
|
|
|
|
|
|
|
|
|
|
#define pa_streq(a,b) (!strcmp((a),(b)))
|
|
|
|
|
|
2009-04-29 01:54:44 +02:00
|
|
|
char *pa_get_host_name_malloc(void);
|
|
|
|
|
char *pa_get_user_name_malloc(void);
|
|
|
|
|
|
2008-08-07 02:22:57 +02:00
|
|
|
char *pa_machine_id(void);
|
2009-04-13 22:20:48 +02:00
|
|
|
char *pa_session_id(void);
|
2008-09-05 15:42:39 +03:00
|
|
|
char *pa_uname_string(void);
|
2008-08-07 02:22:57 +02:00
|
|
|
|
2008-10-04 00:10:43 +02:00
|
|
|
#ifdef HAVE_VALGRIND_MEMCHECK_H
|
|
|
|
|
pa_bool_t pa_in_valgrind(void);
|
|
|
|
|
#else
|
|
|
|
|
static inline pa_bool_t pa_in_valgrind(void) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-01-10 02:53:57 +01:00
|
|
|
unsigned pa_gcd(unsigned a, unsigned b);
|
|
|
|
|
void pa_reduce(unsigned *num, unsigned *den);
|
|
|
|
|
|
2009-01-22 02:16:53 +01:00
|
|
|
unsigned pa_ncpus(void);
|
|
|
|
|
|
2009-02-04 17:19:15 +01:00
|
|
|
char *pa_replace(const char*s, const char*a, const char *b);
|
|
|
|
|
|
2009-07-21 00:02:27 +03:00
|
|
|
/* Escapes p by inserting backslashes in front of backslashes. chars is a
|
|
|
|
|
* regular (ie. NULL-terminated) string containing additional characters that
|
|
|
|
|
* should be escaped. chars can be NULL. The caller has to free the returned
|
|
|
|
|
* string. */
|
|
|
|
|
char *pa_escape(const char *p, const char *chars);
|
|
|
|
|
|
|
|
|
|
/* Does regular backslash unescaping. Returns the argument p. */
|
2009-02-04 17:19:15 +01:00
|
|
|
char *pa_unescape(char *p);
|
|
|
|
|
|
2009-02-18 21:57:57 +01:00
|
|
|
char *pa_realpath(const char *path);
|
|
|
|
|
|
2009-05-25 23:56:38 +02:00
|
|
|
void pa_disable_sigpipe(void);
|
|
|
|
|
|
2009-06-17 03:13:01 +02:00
|
|
|
void pa_xfreev(void**a);
|
|
|
|
|
|
|
|
|
|
static inline void pa_xstrfreev(char **a) {
|
|
|
|
|
pa_xfreev((void**) a);
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-17 03:13:32 +02:00
|
|
|
char **pa_split_spaces_strv(const char *s);
|
|
|
|
|
|
2009-06-17 03:13:59 +02:00
|
|
|
char* pa_maybe_prefix_path(const char *path, const char *prefix);
|
|
|
|
|
|
2009-08-01 01:59:58 +02:00
|
|
|
/* Returns size of the specified pipe or 4096 on failure */
|
|
|
|
|
size_t pa_pipe_buf(int fd);
|
|
|
|
|
|
2009-08-12 21:36:52 +02:00
|
|
|
void pa_reset_personality(void);
|
|
|
|
|
|
2009-08-21 03:43:53 +02:00
|
|
|
#if defined(__linux__) && !defined(__OPTIMIZE__)
|
|
|
|
|
pa_bool_t pa_run_from_build_tree(void);
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-09-17 21:06:54 +02:00
|
|
|
const char *pa_get_temp_dir(void);
|
|
|
|
|
|
2009-10-30 03:30:42 +01:00
|
|
|
int pa_open_cloexec(const char *fn, int flags, mode_t mode);
|
|
|
|
|
int pa_socket_cloexec(int domain, int type, int protocol);
|
|
|
|
|
int pa_pipe_cloexec(int pipefd[2]);
|
|
|
|
|
int pa_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
|
2009-10-30 04:20:24 +01:00
|
|
|
FILE* pa_fopen_cloexec(const char *path, const char *mode);
|
2009-10-30 03:30:42 +01:00
|
|
|
|
2009-10-31 02:43:47 +01:00
|
|
|
void pa_nullify_stdfds(void);
|
|
|
|
|
|
2009-11-05 03:22:15 +01:00
|
|
|
char *pa_read_line_from_file(const char *fn);
|
|
|
|
|
pa_bool_t pa_running_in_vm(void);
|
|
|
|
|
|
2004-06-23 23:17:30 +00:00
|
|
|
#endif
|