misc/libfreetype/src/base/ftutil.c
author unc0rr
Wed, 05 Dec 2012 23:51:04 +0400
branchflibqtfrontend
changeset 8230 bd4b8f9488a4
parent 5172 88f2e05288ba
permissions -rw-r--r--
Show who's in game to spectators
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     1
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     2
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
/*  ftutil.c                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
/*    FreeType utility file for memory and list management (body).         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*  Copyright 2002, 2004, 2005, 2006, 2007 by                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*  This file is part of the FreeType project, and may only be used,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  modified, and distributed under the terms of the FreeType project      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/*  this file you indicate that you have read the license and              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include FT_INTERNAL_MEMORY_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include FT_INTERNAL_OBJECTS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
#include FT_LIST_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
  /* messages during execution.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
#define FT_COMPONENT  trace_memory
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
  /*****               M E M O R Y   M A N A G E M E N T               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
  FT_BASE_DEF( FT_Pointer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
  ft_mem_alloc( FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
                FT_Long    size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
                FT_Error  *p_error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
    FT_Error    error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
    FT_Pointer  block = ft_mem_qalloc( memory, size, &error );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
    if ( !error && size > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
      FT_MEM_ZERO( block, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
    *p_error = error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
    return block;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
  FT_BASE_DEF( FT_Pointer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
  ft_mem_qalloc( FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
                 FT_Long    size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
                 FT_Error  *p_error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
    FT_Error    error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
    FT_Pointer  block = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
    if ( size > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
      block = memory->alloc( memory, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
      if ( block == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
        error = FT_Err_Out_Of_Memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
    else if ( size < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
      /* may help catch/prevent security issues */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
      error = FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
    *p_error = error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
    return block;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
  FT_BASE_DEF( FT_Pointer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
  ft_mem_realloc( FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
                  FT_Long    item_size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
                  FT_Long    cur_count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
                  FT_Long    new_count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
                  void*      block,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
                  FT_Error  *p_error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
    FT_Error  error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
    block = ft_mem_qrealloc( memory, item_size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
                             cur_count, new_count, block, &error );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
    if ( !error && new_count > cur_count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
      FT_MEM_ZERO( (char*)block + cur_count * item_size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
                   ( new_count - cur_count ) * item_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
    *p_error = error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
    return block;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
  FT_BASE_DEF( FT_Pointer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
  ft_mem_qrealloc( FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
                   FT_Long    item_size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
                   FT_Long    cur_count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
                   FT_Long    new_count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
                   void*      block,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
                   FT_Error  *p_error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
    FT_Error  error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
    /* Note that we now accept `item_size == 0' as a valid parameter, in
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
     * order to cover very weird cases where an ALLOC_MULT macro would be
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
     * called.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
    if ( cur_count < 0 || new_count < 0 || item_size < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
      /* may help catch/prevent nasty security issues */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
      error = FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
    else if ( new_count == 0 || item_size == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
      ft_mem_free( memory, block );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
      block = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
    else if ( new_count > FT_INT_MAX/item_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
      error = FT_Err_Array_Too_Large;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
    else if ( cur_count == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
      FT_ASSERT( block == NULL );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
      block = ft_mem_alloc( memory, new_count*item_size, &error );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
      FT_Pointer  block2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
      FT_Long     cur_size = cur_count*item_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
      FT_Long     new_size = new_count*item_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
      block2 = memory->realloc( memory, cur_size, new_size, block );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
      if ( block2 == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
        error = FT_Err_Out_Of_Memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
        block = block2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
    *p_error = error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
    return block;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
  FT_BASE_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
  ft_mem_free( FT_Memory   memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
               const void *P )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
    if ( P )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
      memory->free( memory, (void*)P );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
  FT_BASE_DEF( FT_Pointer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
  ft_mem_dup( FT_Memory    memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
              const void*  address,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
              FT_ULong     size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
              FT_Error    *p_error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
    FT_Error    error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
    FT_Pointer  p = ft_mem_qalloc( memory, size, &error );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
    if ( !error && address )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
      ft_memcpy( p, address, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
    *p_error = error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
    return p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
  FT_BASE_DEF( FT_Pointer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
  ft_mem_strdup( FT_Memory    memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
                 const char*  str,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
                 FT_Error    *p_error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
    FT_ULong  len = str ? (FT_ULong)ft_strlen( str ) + 1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
                        : 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
    return ft_mem_dup( memory, str, len, p_error );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
  FT_BASE_DEF( FT_Int )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
  ft_mem_strcpyn( char*        dst,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
                  const char*  src,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
                  FT_ULong     size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
    while ( size > 1 && *src != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
      *dst++ = *src++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
      size--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
    *dst = 0;  /* always zero-terminate */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
    return *src != 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
  /*****            D O U B L Y   L I N K E D   L I S T S              *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
#define FT_COMPONENT  trace_list
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
  /* documentation is in ftlist.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
  FT_EXPORT_DEF( FT_ListNode )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
  FT_List_Find( FT_List  list,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
                void*    data )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
    FT_ListNode  cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
    cur = list->head;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
    while ( cur )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
      if ( cur->data == data )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
        return cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
      cur = cur->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
    return (FT_ListNode)0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
  /* documentation is in ftlist.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
  FT_List_Add( FT_List      list,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
               FT_ListNode  node )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
    FT_ListNode  before = list->tail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
    node->next = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
    node->prev = before;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
    if ( before )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
      before->next = node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
      list->head = node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
    list->tail = node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
  /* documentation is in ftlist.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
  FT_List_Insert( FT_List      list,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
                  FT_ListNode  node )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
    FT_ListNode  after = list->head;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
    node->next = after;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
    node->prev = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
    if ( !after )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
      list->tail = node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
      after->prev = node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
    list->head = node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
  /* documentation is in ftlist.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
  FT_List_Remove( FT_List      list,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
                  FT_ListNode  node )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
    FT_ListNode  before, after;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
    before = node->prev;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
    after  = node->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
    if ( before )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
      before->next = after;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
      list->head = after;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
    if ( after )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
      after->prev = before;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
      list->tail = before;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
  /* documentation is in ftlist.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
  FT_List_Up( FT_List      list,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
              FT_ListNode  node )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
    FT_ListNode  before, after;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
    before = node->prev;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
    after  = node->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
    /* check whether we are already on top of the list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
    if ( !before )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
    before->next = after;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
    if ( after )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
      after->prev = before;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
      list->tail = before;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
    node->prev       = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
    node->next       = list->head;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
    list->head->prev = node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
    list->head       = node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
  /* documentation is in ftlist.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
  FT_List_Iterate( FT_List            list,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
                   FT_List_Iterator   iterator,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
                   void*              user )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
    FT_ListNode  cur   = list->head;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
    FT_Error     error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
    while ( cur )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
      FT_ListNode  next = cur->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
      error = iterator( cur, user );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
      cur = next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
  /* documentation is in ftlist.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
  FT_List_Finalize( FT_List             list,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
                    FT_List_Destructor  destroy,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
                    FT_Memory           memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
                    void*               user )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
    FT_ListNode  cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
    cur = list->head;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
    while ( cur )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
      FT_ListNode  next = cur->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
      void*        data = cur->data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
      if ( destroy )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
        destroy( memory, data, user );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
      FT_FREE( cur );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
      cur = next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
    list->head = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
    list->tail = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
  FT_BASE_DEF( FT_UInt32 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
  ft_highpow2( FT_UInt32  value )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
    FT_UInt32  value2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
     *  We simply clear the lowest bit in each iteration.  When
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
     *  we reach 0, we know that the previous value was our result.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
    for ( ;; )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
      value2 = value & (value - 1);  /* clear lowest bit */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
      if ( value2 == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
      value = value2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
    return value;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
  FT_BASE_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
  FT_Alloc( FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
            FT_Long    size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
            void*     *P )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
    (void)FT_ALLOC( *P, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
  FT_BASE_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
  FT_QAlloc( FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
             FT_Long    size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
             void*     *p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
    (void)FT_QALLOC( *p, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
  FT_BASE_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
  FT_Realloc( FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
              FT_Long    current,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
              FT_Long    size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
              void*     *P )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
    (void)FT_REALLOC( *P, current, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
  FT_BASE_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
  FT_QRealloc( FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
               FT_Long    current,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
               FT_Long    size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
               void*     *p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
    (void)FT_QREALLOC( *p, current, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
  FT_BASE_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
  FT_Free( FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
           void*     *P )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
    if ( *P )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
      FT_MEM_FREE( *P );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
/* END */