]> code.delx.au - pulseaudio/blob - src/pulsecore/core-util.h
add new pa_get_state_dir() function, move pa_strnull() here
[pulseaudio] / src / pulsecore / core-util.h
1 #ifndef foocoreutilhfoo
2 #define foocoreutilhfoo
3
4 /* $Id$ */
5
6 /***
7 This file is part of PulseAudio.
8
9 Copyright 2004-2006 Lennart Poettering
10 Copyright 2006-2007 Pierre Ossman <ossman@cendio.se> for Cendio AB
11
12 PulseAudio is free software; you can redistribute it and/or modify
13 it under the terms of the GNU Lesser General Public License as
14 published by the Free Software Foundation; either version 2.1 of the
15 License, or (at your option) any later version.
16
17 PulseAudio is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 Lesser General Public License for more details.
21
22 You should have received a copy of the GNU Lesser General Public
23 License along with PulseAudio; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 USA.
26 ***/
27
28 #include <sys/types.h>
29 #include <inttypes.h>
30 #include <stdarg.h>
31 #include <stdio.h>
32
33 #include <pulse/gccmacro.h>
34 #include <pulsecore/macro.h>
35
36 struct timeval;
37
38 void pa_make_fd_nonblock(int fd);
39 void pa_make_fd_cloexec(int fd);
40
41 int pa_make_secure_dir(const char* dir, mode_t m, uid_t uid, gid_t gid);
42 int pa_make_secure_parent_dir(const char *fn, mode_t, uid_t uid, gid_t gid);
43
44 ssize_t pa_read(int fd, void *buf, size_t count, int *type);
45 ssize_t pa_write(int fd, const void *buf, size_t count, int *type);
46 ssize_t pa_loop_read(int fd, void*data, size_t size, int *type);
47 ssize_t pa_loop_write(int fd, const void*data, size_t size, int *type);
48
49 int pa_close(int fd);
50
51 void pa_check_signal_is_blocked(int sig);
52
53 char *pa_sprintf_malloc(const char *format, ...) PA_GCC_PRINTF_ATTR(1,2);
54 char *pa_vsprintf_malloc(const char *format, va_list ap);
55
56 char *pa_strlcpy(char *b, const char *s, size_t l);
57
58 char *pa_parent_dir(const char *fn);
59
60 int pa_make_realtime(int rtprio);
61 int pa_raise_priority(int nice_level);
62 void pa_reset_priority(void);
63
64 int pa_parse_boolean(const char *s) PA_GCC_PURE;
65
66 static inline const char *pa_yes_no(pa_bool_t b) {
67 return b ? "yes" : "no";
68 }
69
70 static inline const char *pa_strnull(const char *x) {
71 return x ? x : "(null)";
72 }
73
74 char *pa_split(const char *c, const char*delimiters, const char **state);
75 char *pa_split_spaces(const char *c, const char **state);
76
77 char *pa_strip_nl(char *s);
78
79 const char *pa_sig2str(int sig) PA_GCC_PURE;
80
81 int pa_own_uid_in_group(const char *name, gid_t *gid);
82 int pa_uid_in_group(uid_t uid, const char *name);
83 gid_t pa_get_gid_of_group(const char *name);
84 int pa_check_in_group(gid_t g);
85
86 int pa_lock_fd(int fd, int b);
87
88 int pa_lock_lockfile(const char *fn);
89 int pa_unlock_lockfile(const char *fn, int fd);
90
91 FILE *pa_open_config_file(const char *global, const char *local, const char *env, char **result, const char *mode);
92
93 char *pa_hexstr(const uint8_t* d, size_t dlength, char *s, size_t slength);
94 size_t pa_parsehex(const char *p, uint8_t *d, size_t dlength);
95
96 int pa_startswith(const char *s, const char *pfx) PA_GCC_PURE;
97 int pa_endswith(const char *s, const char *sfx) PA_GCC_PURE;
98
99 char *pa_runtime_path(const char *fn, char *s, size_t l);
100
101 int pa_atoi(const char *s, int32_t *ret_i);
102 int pa_atou(const char *s, uint32_t *ret_u);
103 int pa_atof(const char *s, float *ret_f);
104
105 int pa_snprintf(char *str, size_t size, const char *format, ...);
106
107 char *pa_truncate_utf8(char *c, size_t l);
108
109 char *pa_getcwd(void);
110 char *pa_make_path_absolute(const char *p);
111
112 void *pa_will_need(const void *p, size_t l);
113
114 static inline int pa_is_power_of_two(unsigned n) {
115 return !(n & (n - 1));
116 }
117
118 static inline unsigned pa_make_power_of_two(unsigned n) {
119 unsigned j = n;
120
121 if (pa_is_power_of_two(n))
122 return n;
123
124 while (j) {
125 j = j >> 1;
126 n = n | j;
127 }
128
129 return n + 1;
130 }
131
132 void pa_close_pipe(int fds[2]);
133
134 char *pa_readlink(const char *p);
135
136 char *pa_get_state_dir(void);
137
138 #endif