Jonathan Gordon | db658d9 | 2010-06-17 08:36:28 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id: skin_buffer.c 25962 2010-05-12 09:31:40Z jdgordon $ |
| 9 | * |
| 10 | * Copyright (C) 2002 by Linus Nielsen Feltzing |
| 11 | * Copyright (C) 2009 Jonathan Gordon |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or |
| 14 | * modify it under the terms of the GNU General Public License |
| 15 | * as published by the Free Software Foundation; either version 2 |
| 16 | * of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 19 | * KIND, either express or implied. |
| 20 | * |
| 21 | ****************************************************************************/ |
| 22 | |
| 23 | #include <stdio.h> |
| 24 | #include <string.h> |
| 25 | #include <stdlib.h> |
| 26 | #ifndef _SKIN_BUFFFER_H_ |
| 27 | #define _SKIN_BUFFFER_H_ |
Jonathan Gordon | 2d31d77 | 2010-07-29 12:37:48 +0000 | [diff] [blame] | 28 | void skin_buffer_init(char* buffer, size_t size); |
Jonathan Gordon | db658d9 | 2010-06-17 08:36:28 +0000 | [diff] [blame] | 29 | /* Allocate size bytes from the buffer */ |
Jonathan Gordon | 7e44438 | 2011-09-25 12:05:03 +0000 | [diff] [blame] | 30 | |
Jonathan Gordon | 9e07ef2 | 2011-11-15 14:11:08 +0000 | [diff] [blame] | 31 | #ifndef __PCTOOL__ |
| 32 | #define INVALID_OFFSET (-1) |
| 33 | #define IS_VALID_OFFSET(o) ((o) >= 0) |
| 34 | long skin_buffer_to_offset(void *pointer); |
| 35 | void* skin_buffer_from_offset(long offset); |
| 36 | #else |
| 37 | #define INVALID_OFFSET (NULL) |
| 38 | #define IS_VALID_OFFSET(o) ((o) != NULL) |
| 39 | #define skin_buffer_to_offset(p) p |
| 40 | #define skin_buffer_from_offset(o) o |
| 41 | #endif |
| 42 | |
Jonathan Gordon | 7e44438 | 2011-09-25 12:05:03 +0000 | [diff] [blame] | 43 | /* #define DEBUG_SKIN_ALLOCATIONS */ |
| 44 | |
| 45 | #ifdef DEBUG_SKIN_ALLOCATIONS |
| 46 | #define FOO(X) #X |
| 47 | #define STRNG(X) FOO(X) |
| 48 | #define skin_buffer_alloc(s) skin_buffer_alloc_ex(s, __FILE__ ":" STRNG(__LINE__)) |
| 49 | void* skin_buffer_alloc_ex(size_t size, char* str); |
| 50 | #else |
Jonathan Gordon | db658d9 | 2010-06-17 08:36:28 +0000 | [diff] [blame] | 51 | void* skin_buffer_alloc(size_t size); |
Jonathan Gordon | 7e44438 | 2011-09-25 12:05:03 +0000 | [diff] [blame] | 52 | #endif |
| 53 | |
Jonathan Gordon | 95b0cef | 2010-06-17 13:54:09 +0000 | [diff] [blame] | 54 | |
| 55 | /* get the number of bytes currently being used */ |
| 56 | size_t skin_buffer_usage(void); |
| 57 | size_t skin_buffer_freespace(void); |
Jonathan Gordon | 2d31d77 | 2010-07-29 12:37:48 +0000 | [diff] [blame] | 58 | |
Jonathan Gordon | db658d9 | 2010-06-17 08:36:28 +0000 | [diff] [blame] | 59 | #endif |