evil-qemacs/cutils.h
2007-12-03 16:10:38 +00:00

89 lines
2.7 KiB
C

/*
* Various simple C utilities
*
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef CUTILS_H
#define CUTILS_H
#include <stdlib.h>
int strstart(const char *str, const char *val, const char **ptr);
int stristart(const char *str, const char *val, const char **ptr);
int stricmp(const char *str1, const char *str2);
void pstrcpy(char *buf, int buf_size, const char *str);
char *pstrcat(char *buf, int buf_size, const char *s);
/* CG: These definitions should be moved to a different header to
* avoid conflict with ffmpeg's cutil module.
*/
char *pstrncpy(char *buf, int buf_size, const char *s, int len);
/* list.c */
/* Double linked lists. Same api as the linux kernel */
struct list_head {
struct list_head *next, *prev;
};
static inline int list_empty(struct list_head *head)
{
return head->next == head;
}
static inline void __list_add(struct list_head *elem,
struct list_head *prev, struct list_head *next)
{
next->prev = elem;
elem->next = next;
prev->next = elem;
elem->prev = prev;
}
static inline void __list_del(struct list_head *prev, struct list_head *next)
{
prev->next = next;
next->prev = prev;
}
#define LIST_HEAD(name) struct list_head name = { &name, &name }
/* add at the head */
#define list_add(elem, head) \
__list_add((struct list_head *)elem, head, (head)->next);
/* add at tail */
#define list_add_tail(elem, head) \
__list_add((struct list_head *)elem, (head)->prev, head)
/* delete */
#define list_del(elem) __list_del(((struct list_head *)elem)->prev, \
((struct list_head *)elem)->next)
#define list_for_each(elem, head) \
for (elem = (void *)(head)->next; elem != (void *)(head); elem = elem->next)
#define list_for_each_safe(elem, elem1, head) \
for (elem = (void *)(head)->next, elem1 = elem->next; elem != (void *)(head); \
elem = elem1, elem1 = elem->next)
#define list_for_each_prev(elem, head) \
for (elem = (void *)(head)->prev; elem != (void *)(head); elem = elem->prev)
#endif