add new pa_readlink() API
[profile/ivi/pulseaudio-panda.git] / 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 <pulsecore/gccmacro.h>
34
35 struct timeval;
36
37 void pa_make_fd_nonblock(int fd);
38 void pa_make_fd_cloexec(int fd);
39
40 int pa_make_secure_dir(const char* dir, mode_t m, uid_t uid, gid_t gid);
41 int pa_make_secure_parent_dir(const char *fn, mode_t, uid_t uid, gid_t gid);
42
43 ssize_t pa_read(int fd, void *buf, size_t count, int *type);
44 ssize_t pa_write(int fd, const void *buf, size_t count, int *type);
45 ssize_t pa_loop_read(int fd, void*data, size_t size, int *type);
46 ssize_t pa_loop_write(int fd, const void*data, size_t size, int *type);
47
48 int pa_close(int fd);
49
50 void pa_check_signal_is_blocked(int sig);
51
52 char *pa_sprintf_malloc(const char *format, ...) PA_GCC_PRINTF_ATTR(1,2);
53 char *pa_vsprintf_malloc(const char *format, va_list ap);
54
55 char *pa_strlcpy(char *b, const char *s, size_t l);
56
57 char *pa_parent_dir(const char *fn);
58
59 void pa_make_realtime(void);
60 void pa_raise_priority(void);
61 void pa_reset_priority(void);
62
63 int pa_parse_boolean(const char *s) PA_GCC_PURE;
64
65 char *pa_split(const char *c, const char*delimiters, const char **state);
66 char *pa_split_spaces(const char *c, const char **state);
67
68 char *pa_strip_nl(char *s);
69
70 const char *pa_sig2str(int sig) PA_GCC_PURE;
71
72 int pa_own_uid_in_group(const char *name, gid_t *gid);
73 int pa_uid_in_group(uid_t uid, const char *name);
74 gid_t pa_get_gid_of_group(const char *name);
75 int pa_check_in_group(gid_t g);
76
77 int pa_lock_fd(int fd, int b);
78
79 int pa_lock_lockfile(const char *fn);
80 int pa_unlock_lockfile(const char *fn, int fd);
81
82 FILE *pa_open_config_file(const char *global, const char *local, const char *env, char **result, const char *mode);
83
84 char *pa_hexstr(const uint8_t* d, size_t dlength, char *s, size_t slength);
85 size_t pa_parsehex(const char *p, uint8_t *d, size_t dlength);
86
87 int pa_startswith(const char *s, const char *pfx) PA_GCC_PURE;
88 int pa_endswith(const char *s, const char *sfx) PA_GCC_PURE;
89
90 char *pa_runtime_path(const char *fn, char *s, size_t l);
91
92 int pa_atoi(const char *s, int32_t *ret_i);
93 int pa_atou(const char *s, uint32_t *ret_u);
94 int pa_atof(const char *s, float *ret_f);
95
96 int pa_snprintf(char *str, size_t size, const char *format, ...);
97
98 char *pa_truncate_utf8(char *c, size_t l);
99
100 char *pa_getcwd(void);
101 char *pa_make_path_absolute(const char *p);
102
103 void *pa_will_need(const void *p, size_t l);
104
105 static inline int pa_is_power_of_two(unsigned n) {
106     return !(n & (n - 1));
107 }
108
109 static inline unsigned pa_make_power_of_two(unsigned n) {
110     unsigned j = n;
111
112     if (pa_is_power_of_two(n))
113         return n;
114
115     while (j) {
116         j = j >> 1;
117         n = n | j;
118     }
119
120     return n + 1;
121 }
122
123 void pa_close_pipe(int fds[2]);
124
125 char *pa_readlink(const char *p);
126
127 #endif