]>
code.delx.au - pulseaudio/blob - src/util.c
10 #include <sys/types.h>
14 void pa_make_nonblock_fd(int fd
) {
17 if ((v
= fcntl(fd
, F_GETFL
)) >= 0)
18 if (!(v
& O_NONBLOCK
))
19 fcntl(fd
, F_SETFL
, v
|O_NONBLOCK
);
22 int pa_make_secure_dir(const char* dir
) {
25 if (mkdir(dir
, 0700) < 0)
29 if (lstat(dir
, &st
) < 0)
32 if (!S_ISDIR(st
.st_mode
) || (st
.st_uid
!= getuid()) || ((st
.st_mode
& 0777) != 0700))
42 ssize_t
pa_loop_read(int fd
, void*data
, size_t size
) {
44 assert(fd
>= 0 && data
&& size
);
49 if ((r
= read(fd
, data
, size
)) < 0)
63 ssize_t
pa_loop_write(int fd
, const void*data
, size_t size
) {
65 assert(fd
>= 0 && data
&& size
);
70 if ((r
= write(fd
, data
, size
)) < 0)
84 void pa_check_for_sigpipe(void) {
87 if (sigaction(SIGPIPE
, NULL
, &sa
) < 0) {
88 fprintf(stderr
, __FILE__
": sigaction() failed: %s\n", strerror(errno
));
92 if (sa
.sa_handler
== SIG_DFL
)
93 fprintf(stderr
, "polypaudio: WARNING: SIGPIPE is not trapped. This might cause malfunction!\n");
96 /* The following is based on an example from the GNU libc documentation */
97 char *pa_sprintf_malloc(const char *format
, ...) {
107 c
= realloc(c
, size
);
110 va_start(ap
, format
);
111 r
= vsnprintf(c
, size
, format
, ap
);
114 if (r
> -1 && r
< size
)
117 if (r
> -1) /* glibc 2.1 */