2004-02-24 00:41:20 +01:00
|
|
|
/* the Music Player Daemon (MPD)
|
2007-04-05 05:22:33 +02:00
|
|
|
* Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
|
2004-02-24 00:41:20 +01:00
|
|
|
* This project's homepage is: http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef UTILS_H
|
|
|
|
#define UTILS_H
|
|
|
|
|
2006-08-26 08:25:57 +02:00
|
|
|
#include "gcc.h"
|
2008-01-03 08:29:49 +01:00
|
|
|
#include "os_compat.h"
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2006-07-31 01:32:47 +02:00
|
|
|
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
char *myFgets(char *buffer, int bufferSize, FILE * fp);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2007-12-28 03:56:25 +01:00
|
|
|
char *string_toupper(char *str);
|
|
|
|
|
|
|
|
char *strDupToUpper(char *str); /* avoid, use string_toupper instead */
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
void stripReturnChar(char *string);
|
2004-03-09 21:55:51 +01:00
|
|
|
|
2004-04-01 05:48:51 +02:00
|
|
|
void my_usleep(long usec);
|
|
|
|
|
2006-08-20 02:50:44 +02:00
|
|
|
int ipv6Supported(void);
|
2004-05-15 23:19:43 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
char *appendToString(char *dest, const char *src);
|
2004-06-12 04:06:16 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
unsigned long readLEuint32(const unsigned char *p);
|
2005-03-07 01:51:21 +01:00
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
/* trivial functions, keep them inlined */
|
|
|
|
static inline void xclose(int fd)
|
|
|
|
{
|
|
|
|
while (close(fd) && errno == EINTR);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline ssize_t xread(int fd, void *buf, size_t len)
|
|
|
|
{
|
|
|
|
ssize_t nr;
|
|
|
|
while (1) {
|
|
|
|
nr = read(fd, buf, len);
|
|
|
|
if ((nr < 0) && (errno == EAGAIN || errno == EINTR))
|
|
|
|
continue;
|
|
|
|
return nr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline ssize_t xwrite(int fd, const void *buf, size_t len)
|
|
|
|
{
|
|
|
|
ssize_t nr;
|
|
|
|
while (1) {
|
|
|
|
nr = write(fd, buf, len);
|
|
|
|
if ((nr < 0) && (errno == EAGAIN || errno == EINTR))
|
|
|
|
continue;
|
|
|
|
return nr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-26 08:25:57 +02:00
|
|
|
mpd_malloc char *xstrdup(const char *s);
|
|
|
|
|
|
|
|
mpd_malloc void *xmalloc(size_t size);
|
|
|
|
|
|
|
|
mpd_malloc void *xrealloc(void *ptr, size_t size);
|
|
|
|
|
|
|
|
mpd_malloc void *xcalloc(size_t nmemb, size_t size);
|
|
|
|
|
2008-08-29 09:38:08 +02:00
|
|
|
/**
|
|
|
|
* free a const pointer - unfortunately free() expects a non-const
|
|
|
|
* pointer, for whatever reason
|
|
|
|
*/
|
|
|
|
static inline void xfree(const void *p)
|
|
|
|
{
|
|
|
|
union {
|
|
|
|
const void *in;
|
|
|
|
void *out;
|
|
|
|
} deconst = { .in = p };
|
|
|
|
free(deconst.out);
|
|
|
|
}
|
|
|
|
|
2007-06-13 17:27:09 +02:00
|
|
|
char *parsePath(char *path);
|
|
|
|
|
2008-03-26 11:39:03 +01:00
|
|
|
int set_nonblocking(int fd);
|
|
|
|
|
2008-06-30 04:43:04 +02:00
|
|
|
void init_async_pipe(int file_des[2]);
|
|
|
|
|
2008-06-30 04:43:17 +02:00
|
|
|
void xpthread_mutex_init(pthread_mutex_t *m, const pthread_mutexattr_t *a);
|
|
|
|
|
|
|
|
void xpthread_cond_init(pthread_cond_t *c, pthread_condattr_t *a);
|
|
|
|
|
2008-06-30 04:43:04 +02:00
|
|
|
void xpthread_mutex_destroy(pthread_mutex_t *mutex);
|
|
|
|
|
|
|
|
void xpthread_cond_destroy(pthread_cond_t *cond);
|
|
|
|
|
2008-09-23 20:48:08 +02:00
|
|
|
int prefixcmp(const char *str, const char *prefix);
|
|
|
|
|
2004-02-24 00:41:20 +01:00
|
|
|
#endif
|