misc/libfreetype/builds/vms/ftsystem.c
author nemo
Thu, 04 Apr 2013 08:10:59 -0400
changeset 8848 e9ebd63f8a03
parent 5172 88f2e05288ba
permissions -rw-r--r--
So. Some themes have objects that seem to be large natural extensions of the landscape. Masks allow maintaining that. Lemme know if it doesn't look good. If it doesn't, can still use for ice/bounce/indestructible. Indestructible bunker object for example.
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
/*    VMS-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, 2005, 2010 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_OBJECTS_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
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
  /*                       MEMORY MANAGEMENT INTERFACE                     */
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
  /*************************************************************************/
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
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
  /*    ft_alloc                                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
  /*    The memory allocation function.                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
  /*    memory :: A pointer to the memory object.                          */
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
  /*    size   :: The requested size in bytes.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
  /*    The address of newly allocated block.                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
  FT_CALLBACK_DEF( void* )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
  ft_alloc( FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
            long       size )
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_UNUSED( memory );
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
    return malloc( size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
  }
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
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
  /*    ft_realloc                                                         */
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
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
  /*    The memory reallocation function.                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
  /*    memory   :: A pointer to the memory object.                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
  /*    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
   117
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
  /*    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
   119
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
  /*    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
   121
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
  /*    The address of the reallocated memory block.                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
  FT_CALLBACK_DEF( void* )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
  ft_realloc( FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
              long       cur_size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
              long       new_size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
              void*      block )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
    FT_UNUSED( memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
    FT_UNUSED( cur_size );
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
    return realloc( block, new_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
  }
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
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
  /*    ft_free                                                            */
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
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
  /*    The memory release function.                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
  /*    memory :: A pointer to the memory object.                          */
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
  /*    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
   150
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
  FT_CALLBACK_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
  ft_free( FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
           void*      block )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
    FT_UNUSED( memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
    free( block );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
  }
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
  /*                     RESOURCE MANAGEMENT INTERFACE                     */
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
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
  /* 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
   171
  /* 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
   172
  /* messages during execution.                                            */
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
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
#define FT_COMPONENT  trace_io
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
  /* 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
   178
  /* 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
   179
#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
   180
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
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
  /*    ft_close_stream                                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
  /*    The function to close a stream.                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
  /*    stream :: A pointer to the stream object.                          */
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_CALLBACK_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
  ft_close_stream( FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
    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
   197
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
    stream->descriptor.pointer = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
    stream->size               = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
    stream->base               = 0;
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
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
  /* documentation is in ftobjs.h */
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_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
  FT_Stream_Open( FT_Stream    stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
                  const char*  filepathname )
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
    int          file;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
    struct stat  stat_buf;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
    if ( !stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
      return FT_Err_Invalid_Stream_Handle;
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
    /* open the file */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
    file = open( filepathname, O_RDONLY );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
    if ( file < 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
      FT_ERROR(( "FT_Stream_Open:" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
      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
   223
      return FT_Err_Cannot_Open_Resource;
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
    if ( fstat( file, &stat_buf ) < 0 )
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
      FT_ERROR(( "FT_Stream_Open:" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
      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
   230
      goto Fail_Map;
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
    stream->size = stat_buf.st_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
    if ( !stream->size )
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
      FT_ERROR(( "FT_Stream_Open:" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
      FT_ERROR(( " opened `%s' but zero-sized\n", filepathname ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
      goto Fail_Map;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
    stream->pos  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
    stream->base = (unsigned char *)mmap( NULL,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
                                          stream->size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
                                          PROT_READ,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
                                          MAP_FILE | MAP_PRIVATE,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
                                          file,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
                                          0 );
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
    if ( (long)stream->base == -1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
      FT_ERROR(( "FT_Stream_Open:" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
      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
   253
      goto Fail_Map;
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
    close( file );
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
    stream->descriptor.pointer = stream->base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
    stream->pathname.pointer   = (char*)filepathname;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
    stream->close = ft_close_stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
    stream->read  = 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_TRACE1(( "FT_Stream_Open:" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
    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
   266
                filepathname, stream->size ));
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
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
  Fail_Map:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
    close( file );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
    stream->base = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
    stream->size = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
    stream->pos  = 0;
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
    return FT_Err_Cannot_Open_Stream;
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
#ifdef FT_DEBUG_MEMORY
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
  extern FT_Int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
  ft_mem_debug_init( FT_Memory  memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
  extern void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
  ft_mem_debug_done( FT_Memory  memory );
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
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
  /* documentation is in ftobjs.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
  FT_BASE_DEF( FT_Memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
  FT_New_Memory( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
    FT_Memory  memory;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
    memory = (FT_Memory)malloc( sizeof ( *memory ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
    if ( memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
      memory->user    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
      memory->alloc   = ft_alloc;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
      memory->realloc = ft_realloc;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
      memory->free    = ft_free;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
#ifdef FT_DEBUG_MEMORY
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
      ft_mem_debug_init( memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
#endif
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
    return memory;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
  /* documentation is in ftobjs.h */
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
  FT_BASE_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
  FT_Done_Memory( FT_Memory  memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
#ifdef FT_DEBUG_MEMORY
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
    ft_mem_debug_done( memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
    memory->free( memory, memory );
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
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
/* END */