misc/libfreetype/builds/unix/ftsystem.c
author unc0rr
Fri, 25 Jan 2013 22:33:26 +0400
changeset 8436 b89aacebb9db
parent 5172 88f2e05288ba
permissions -rw-r--r--
- Also pass unknown cmds to the server when in room - Fix some warnings
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
/*  ftsystem.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
/*    Unix-specific FreeType low-level system interface (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 1996-2001, 2002, 2004, 2005, 2006, 2007, 2008 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
  /* we use our special ftconfig.h file, not the standard one */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include <ftconfig.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
#include FT_SYSTEM_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
#include FT_ERRORS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
#include FT_TYPES_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
#include FT_INTERNAL_STREAM_H
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
  /* memory-mapping includes and definitions */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
#ifdef HAVE_UNISTD_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
#include <unistd.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
#include <sys/mman.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
#ifndef MAP_FILE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
#define MAP_FILE  0x00
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
#endif
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
#ifdef MUNMAP_USES_VOIDP
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
#define MUNMAP_ARG_CAST  void *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
#define MUNMAP_ARG_CAST  char *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
#endif
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
#ifdef NEED_MUNMAP_DECL
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
#ifdef __cplusplus
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
  extern "C"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
  extern
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
  int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
  munmap( char*  addr,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
          int    len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
#define MUNMAP_ARG_CAST  char *
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
#endif /* NEED_DECLARATION_MUNMAP */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
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
#include <sys/types.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
#include <sys/stat.h>
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
#ifdef HAVE_FCNTL_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
#include <fcntl.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
#include <stdio.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
#include <stdlib.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
#include <string.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
#include <errno.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
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
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
  /*                       MEMORY MANAGEMENT INTERFACE                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
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
  /*************************************************************************/
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
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
  /*    ft_alloc                                                           */
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
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
  /*    The memory allocation function.                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
  /*    memory :: A pointer to the memory object.                          */
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
  /*    size   :: The requested size in bytes.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
  /*    The address of newly allocated block.                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
  FT_CALLBACK_DEF( void* )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
  ft_alloc( FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
            long       size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
    FT_UNUSED( memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
    return malloc( size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
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
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
  /*    ft_realloc                                                         */
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
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
  /*    The memory reallocation function.                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
  /*    memory   :: A pointer to the memory object.                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
  /*    cur_size :: The current size of the allocated memory block.        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
  /*    new_size :: The newly requested size in bytes.                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
  /*    block    :: The current address of the block in memory.            */
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
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
  /*    The address of the reallocated memory block.                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
  FT_CALLBACK_DEF( void* )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
  ft_realloc( FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
              long       cur_size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
              long       new_size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
              void*      block )
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
    FT_UNUSED( memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
    FT_UNUSED( cur_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
    return realloc( block, new_size );
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
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
  /*************************************************************************/
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
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
  /*    ft_free                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
  /*    The memory release function.                                       */
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
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
  /*    memory :: A pointer to the memory object.                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
  /*    block  :: The address of block in memory to be freed.              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
  FT_CALLBACK_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
  ft_free( FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
           void*      block )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
    FT_UNUSED( memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
    free( block );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
  /*************************************************************************/
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
  /*                     RESOURCE MANAGEMENT INTERFACE                     */
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
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
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
  /* 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
   172
  /* 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
   173
  /* messages during execution.                                            */
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
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
#define FT_COMPONENT  trace_io
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
  /* We use the macro STREAM_FILE for convenience to extract the       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
  /* system-specific stream handle from a given FreeType stream object */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
#define STREAM_FILE( stream )  ( (FILE*)stream->descriptor.pointer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
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
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
  /*    ft_close_stream_by_munmap                                          */
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
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
  /*    The function to close a stream which is opened by mmap.            */
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
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
  /*    stream :: A pointer to the stream object.                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
  FT_CALLBACK_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
  ft_close_stream_by_munmap( FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
    munmap( (MUNMAP_ARG_CAST)stream->descriptor.pointer, stream->size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
    stream->descriptor.pointer = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
    stream->size               = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
    stream->base               = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
  }
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
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
  /*    ft_close_stream_by_free                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
  /*    The function to close a stream which is created by ft_alloc.       */
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
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
  /*    stream :: A pointer to the stream object.                          */
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
  FT_CALLBACK_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
  ft_close_stream_by_free( FT_Stream  stream )
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
    ft_free( NULL, stream->descriptor.pointer );
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
    stream->descriptor.pointer = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
    stream->size               = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
    stream->base               = 0;
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
  /* documentation is in ftobjs.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
  FT_BASE_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
  FT_Stream_Open( FT_Stream    stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
                  const char*  filepathname )
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
    int          file;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
    struct stat  stat_buf;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
    if ( !stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
      return FT_Err_Invalid_Stream_Handle;
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
    /* open the file */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
    file = open( filepathname, O_RDONLY );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
    if ( file < 0 )
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_ERROR(( "FT_Stream_Open:" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
      FT_ERROR(( " could not open `%s'\n", filepathname ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
      return FT_Err_Cannot_Open_Resource;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
    /* Here we ensure that a "fork" will _not_ duplicate   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
    /* our opened input streams on Unix.  This is critical */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
    /* since it avoids some (possible) access control      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
    /* issues and cleans up the kernel file table a bit.   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
    /*                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
#ifdef F_SETFD
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
#ifdef FD_CLOEXEC
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
    (void)fcntl( file, F_SETFD, FD_CLOEXEC );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
    (void)fcntl( file, F_SETFD, 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
#endif /* FD_CLOEXEC */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
#endif /* F_SETFD */
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
    if ( fstat( file, &stat_buf ) < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
      FT_ERROR(( "FT_Stream_Open:" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
      FT_ERROR(( " could not `fstat' file `%s'\n", filepathname ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
      goto Fail_Map;
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
    /* XXX: TODO -- real 64bit platform support                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
    /*                                                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
    /* `stream->size' is typedef'd to unsigned long (in                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
    /* freetype/ftsystem.h); `stat_buf.st_size', however, is usually   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
    /* typedef'd to off_t (in sys/stat.h).                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
    /* On some platforms, the former is 32bit and the latter is 64bit. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
    /* To avoid overflow caused by fonts in huge files larger than     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
    /* 2GB, do a test.  Temporary fix proposed by Sean McBride.        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
    /*                                                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
    if ( stat_buf.st_size > LONG_MAX )
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
      FT_ERROR(( "FT_Stream_Open: file is too big\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
      goto Fail_Map;
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
    else if ( stat_buf.st_size == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
      FT_ERROR(( "FT_Stream_Open: zero-length file\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
      goto Fail_Map;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
    }
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
    /* This cast potentially truncates a 64bit to 32bit! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
    stream->size = (unsigned long)stat_buf.st_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
    stream->pos  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
    stream->base = (unsigned char *)mmap( NULL,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
                                          stream->size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
                                          PROT_READ,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
                                          MAP_FILE | MAP_PRIVATE,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
                                          file,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
                                          0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
    /* on some RTOS, mmap might return 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
    if ( (long)stream->base != -1 && stream->base != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
      stream->close = ft_close_stream_by_munmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
    else
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
      ssize_t  total_read_count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
      FT_ERROR(( "FT_Stream_Open:" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
      FT_ERROR(( " could not `mmap' file `%s'\n", filepathname ));
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
      stream->base = (unsigned char*)ft_alloc( NULL, stream->size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
      if ( !stream->base )
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
        FT_ERROR(( "FT_Stream_Open:" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
        FT_ERROR(( " could not `alloc' memory\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
        goto Fail_Map;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
      }
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
      total_read_count = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
      do {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
        ssize_t  read_count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
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
        read_count = read( file,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
                           stream->base + total_read_count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
                           stream->size - total_read_count );
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
        if ( read_count <= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
          if ( read_count == -1 && errno == EINTR )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
            continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
          FT_ERROR(( "FT_Stream_Open:" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
          FT_ERROR(( " error while `read'ing file `%s'\n", filepathname ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
          goto Fail_Read;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
        }
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
        total_read_count += read_count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
      } while ( (unsigned long)total_read_count != stream->size );
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
      stream->close = ft_close_stream_by_free;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
    close( file );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
    stream->descriptor.pointer = stream->base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
    stream->pathname.pointer   = (char*)filepathname;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
    stream->read = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
    FT_TRACE1(( "FT_Stream_Open:" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
    FT_TRACE1(( " opened `%s' (%d bytes) successfully\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
                filepathname, stream->size ));
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
    return FT_Err_Ok;
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
  Fail_Read:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
    ft_free( NULL, stream->base );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
  Fail_Map:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
    close( file );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
    stream->base = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
    stream->size = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
    stream->pos  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
    return FT_Err_Cannot_Open_Stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
  }
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
#ifdef FT_DEBUG_MEMORY
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
  extern FT_Int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
  ft_mem_debug_init( FT_Memory  memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
  extern void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
  ft_mem_debug_done( FT_Memory  memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
#endif
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 ftobjs.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_BASE_DEF( FT_Memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
  FT_New_Memory( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
  {
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
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
    memory = (FT_Memory)malloc( sizeof ( *memory ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
    if ( memory )
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
      memory->user    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
      memory->alloc   = ft_alloc;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
      memory->realloc = ft_realloc;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
      memory->free    = ft_free;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
#ifdef FT_DEBUG_MEMORY
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
      ft_mem_debug_init( memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
    return memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
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
  /* documentation is in ftobjs.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
  FT_BASE_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
  FT_Done_Memory( FT_Memory  memory )
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
#ifdef FT_DEBUG_MEMORY
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
    ft_mem_debug_done( memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
    memory->free( memory, memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
  }
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
/* END */