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
|
|
|
|
|
2004-03-18 04:29:25 +01:00
|
|
|
#include "../config.h"
|
2006-08-26 08:25:57 +02:00
|
|
|
#include "gcc.h"
|
2004-03-18 04:29:25 +01:00
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
2004-02-24 00:41:20 +01:00
|
|
|
#include <stdio.h>
|
2006-07-30 05:43:38 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.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);
|
|
|
|
|
2007-06-13 17:27:09 +02:00
|
|
|
char *parsePath(char *path);
|
|
|
|
|
2004-02-24 00:41:20 +01:00
|
|
|
#endif
|