]> Dogcows Code - chaz/thecheat/blob - CheaterTypes.m
update contact information and project URL
[chaz/thecheat] / CheaterTypes.m
1
2 /*
3 * The Cheat - The legendary universal game trainer for Mac OS X.
4 * http://www.brokenzipper.com/trac/wiki/TheCheat
5 *
6 * Copyright (c) 2003-2011, Charles McGarvey et al.
7 *
8 * Distributable under the terms and conditions of the 2-clause BSD
9 * license; see the file COPYING for the legal text of the license.
10 */
11
12
13 #import "CheaterTypes.h"
14
15
16 TCArray TCMakeArray( unsigned count, unsigned size )
17 {
18 TCArray array = (TCArray)malloc( sizeof(struct _TCArray) );
19
20 if ( array ) {
21 array->_bytes = malloc( count * size );
22
23 if ( array->_bytes ) {
24 array->_count = count;
25 array->_size = size;
26 array->_ownsBytes = YES;
27 }
28 else {
29 free( array );
30 return NULL;
31 }
32 }
33 return array;
34 }
35
36 TCArray TCMakeArrayWithBytes( unsigned count, unsigned size, void *bytes )
37 {
38 TCArray array = TCMakeArray( count, size );
39
40 if ( array && bytes ) {
41 memcpy( array->_bytes, bytes, count * size );
42 }
43 return array;
44 }
45
46 void TCReleaseArray( TCArray array )
47 {
48 if ( array && array->_ownsBytes ) {
49 free( array->_bytes );
50 free( array );
51 }
52 }
53
54
55 void TCArrayAppendArray( TCArray array, TCArray other )
56 {
57 unsigned oldCount = array->_count;
58 unsigned count = oldCount + other->_count;
59
60 if ( array->_size != other->_size ) {
61 return;
62 }
63
64 TCArrayResize( array, count );
65 if ( array->_count == count ) {
66 memcpy( array->_bytes + oldCount * array->_size, other->_bytes, other->_count * other->_size );
67 }
68 }
69
70
71 NSString *TCStringFromArray( TCArray array )
72 {
73 return [NSString stringWithFormat:@"{%p,%u,%u}", array->_bytes, array->_count, array->_size];
74 }
75
76
This page took 0.032877 seconds and 4 git commands to generate.