~alan-griffiths/compiz-core/Bug-931283

« back to all changes in this revision

Viewing changes to src/privates.c

  • Committer: David Reveman
  • Date: 2006-02-09 06:03:09 UTC
  • Revision ID: git-v1:9959c2b13ded64a5e66359a8097250dc9d87fc1c
Initial revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2005 Novell, Inc.
 
3
 *
 
4
 * Permission to use, copy, modify, distribute, and sell this software
 
5
 * and its documentation for any purpose is hereby granted without
 
6
 * fee, provided that the above copyright notice appear in all copies
 
7
 * and that both that copyright notice and this permission notice
 
8
 * appear in supporting documentation, and that the name of
 
9
 * Novell, Inc. not be used in advertising or publicity pertaining to
 
10
 * distribution of the software without specific, written prior permission.
 
11
 * Novell, Inc. makes no representations about the suitability of this
 
12
 * software for any purpose. It is provided "as is" without express or
 
13
 * implied warranty.
 
14
 *
 
15
 * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
16
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
 
17
 * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
18
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
 
19
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 
20
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 
21
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
22
 *
 
23
 * Author: David Reveman <davidr@novell.com>
 
24
 */
 
25
 
 
26
#include <stdlib.h>
 
27
 
 
28
#include <compiz.h>
 
29
 
 
30
int
 
31
allocatePrivateIndex (int                 *len,
 
32
                      char                **indices,
 
33
                      ReallocPrivatesProc reallocProc,
 
34
                      void                *closure)
 
35
{
 
36
    char *newIndices;
 
37
    int  i;
 
38
 
 
39
    for (i = 0; i < *len; i++)
 
40
    {
 
41
        if (!(*indices)[i])
 
42
        {
 
43
            (*indices)[i] = 1;
 
44
            return i;
 
45
        }
 
46
    }
 
47
 
 
48
    newIndices = (char *) realloc (*indices, (*len + 1) * sizeof (char));
 
49
    if (!newIndices)
 
50
        return -1;
 
51
 
 
52
    newIndices[*len] = 1;
 
53
    *indices = newIndices;
 
54
 
 
55
    if (!(*reallocProc) (*len + 1, closure))
 
56
        return -1;
 
57
 
 
58
    return (*len)++;
 
59
}
 
60
 
 
61
void
 
62
freePrivateIndex (int  len,
 
63
                  char *indices,
 
64
                  int  index)
 
65
{
 
66
    if (index < len)
 
67
        indices[index] = 0;
 
68
}