~ubuntu-branches/ubuntu/jaunty/transmission/jaunty-security

« back to all changes in this revision

Viewing changes to libtransmission/ptrarray.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Starr-Bochicchio, Andrew Starr-Bochicchio, Martin Pitt
  • Date: 2009-02-26 11:55:50 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20090226115550-3rnhgt9qhe3y6g74
Tags: 1.50-1ubuntu1
[ Andrew Starr-Bochicchio ]
* Merge from debian unstable (LP: #329161), remaining changes:
 - debian/control: 
  + Added replaces & provides clutch (now included as part of transmission).
  + Build-depends on quilt.
 - debian/rules: 
  + Uncommented "include /usr/share/quilt/quilt.make".
  + Added patch/unpatch targets for Quilt.
  + Create a PO template during package build.
 - 20_add_X-Ubuntu-Gettext-Domain.diff: Add X-Ubuntu-Gettext-Domain 
   to .desktop file.

[ Martin Pitt ]
* Add 01_check_notification_actions.diff: Check if notification
  agent supports actions, and do not use actions if not. (LP: #334252)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * This file Copyright (C) 2008 Charles Kerr <charles@rebelbase.com>
 
2
 * This file Copyright (C) 2008-2009 Charles Kerr <charles@transmissionbt.com>
3
3
 *
4
4
 * This file is licensed by the GPL version 2.  Works owned by the
5
5
 * Transmission project are granted a special exemption to clause 2(b)
7
7
 * This exemption does not extend to derived works not owned by
8
8
 * the Transmission project.
9
9
 *
10
 
 * $Id: ptrarray.c 6953 2008-10-25 02:15:37Z charles $
 
10
 * $Id: ptrarray.c 7664 2009-01-11 17:46:51Z charles $
11
11
 */
12
12
 
13
13
#include <assert.h>
19
19
 
20
20
#define GROW 32
21
21
 
22
 
struct tr_ptrArray
 
22
const tr_ptrArray TR_PTR_ARRAY_INIT = { NULL, 0, 0 };
 
23
 
 
24
void
 
25
tr_ptrArrayDestruct( tr_ptrArray * p, PtrArrayForeachFunc func )
23
26
{
24
 
    void ** items;
25
 
    int     n_items;
26
 
    int     n_alloc;
27
 
};
 
27
    assert( p );
 
28
    assert( p->items || !p->n_items );
 
29
 
 
30
    if( func )
 
31
        tr_ptrArrayForeach( p, func );
 
32
 
 
33
    tr_free( p->items );
 
34
 
 
35
    memset( p, ~0, sizeof( tr_ptrArray ) );
 
36
}
28
37
 
29
38
tr_ptrArray*
30
39
tr_ptrArrayNew( void )
31
40
{
32
 
    tr_ptrArray * p;
33
 
 
34
 
    p = tr_new( tr_ptrArray, 1 );
35
 
    p->n_items = 0;
36
 
    p->n_alloc = 0;
37
 
    p->items = NULL;
38
 
 
 
41
    tr_ptrArray * p = tr_new( tr_ptrArray, 1 );
 
42
    *p = TR_PTR_ARRAY_INIT;
39
43
    return p;
40
44
}
41
45
 
69
73
tr_ptrArrayFree( tr_ptrArray *       t,
70
74
                 PtrArrayForeachFunc func )
71
75
{
72
 
    assert( t );
73
 
    assert( t->items || !t->n_items );
74
 
 
75
 
    if( func )
76
 
        tr_ptrArrayForeach( t, func );
77
 
 
78
 
    tr_free( t->items );
 
76
    tr_ptrArrayDestruct( t, func );
79
77
    tr_free( t );
80
78
}
81
79
 
87
85
    return t->items;
88
86
}
89
87
 
90
 
void**
91
 
tr_ptrArrayBase( tr_ptrArray * t )
92
 
{
93
 
    return t->items;
94
 
}
95
 
 
96
88
void*
97
89
tr_ptrArrayNth( tr_ptrArray* t,
98
90
                int          i )
113
105
}
114
106
 
115
107
int
116
 
tr_ptrArraySize( const tr_ptrArray * t )
117
 
{
118
 
    return t->n_items;
119
 
}
120
 
 
121
 
int
122
 
tr_ptrArrayEmpty( const tr_ptrArray * t )
123
 
{
124
 
    return t->n_items == 0;
125
 
}
126
 
 
127
 
void
128
 
tr_ptrArrayClear( tr_ptrArray * t )
129
 
{
130
 
    t->n_items = 0;
131
 
}
132
 
 
133
 
int
134
108
tr_ptrArrayInsert( tr_ptrArray * t,
135
 
                   void *        ptr,
 
109
                   void        * ptr,
136
110
                   int           pos )
137
111
{
138
112
    if( pos < 0 || pos > t->n_items )
145
119
    }
146
120
 
147
121
    memmove( t->items + pos + 1,
148
 
            t->items + pos,
149
 
            sizeof( void* ) * ( t->n_items - pos ) );
 
122
             t->items + pos,
 
123
             sizeof( void* ) * ( t->n_items - pos ) );
150
124
 
151
125
    t->items[pos] = ptr;
152
126
    t->n_items++;
153
127
    return pos;
154
128
}
155
129
 
156
 
int
157
 
tr_ptrArrayAppend( tr_ptrArray * t,
158
 
                   void *        ptr )
159
 
{
160
 
    return tr_ptrArrayInsert( t, ptr, -1 );
161
 
}
162
 
 
163
130
void*
164
131
tr_ptrArrayPop( tr_ptrArray* t )
165
132
{
238
205
    int i;
239
206
 
240
207
    for( i = 0; i < t->n_items - 2; ++i )
241
 
        assert( compare( t->items[i], t->items[i + 1] ) < 0 );
 
208
        assert( compare( t->items[i], t->items[i + 1] ) <= 0 );
242
209
}
243
210
 
244
211
int