2000-07-20 08:57:41 +02:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* ftsystem.c */
|
|
|
|
/* */
|
|
|
|
/* Unix-specific FreeType low-level system interface (body). */
|
|
|
|
/* */
|
2005-11-18 09:23:06 +01:00
|
|
|
/* Copyright 1996-2001, 2002, 2004, 2005 by */
|
2000-07-20 08:57:41 +02:00
|
|
|
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
|
|
|
|
/* */
|
|
|
|
/* This file is part of the FreeType project, and may only be used, */
|
|
|
|
/* modified, and distributed under the terms of the FreeType project */
|
|
|
|
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
|
|
|
|
/* this file you indicate that you have read the license and */
|
|
|
|
/* understand and accept it fully. */
|
|
|
|
/* */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
|
* include/freetype/config/ft2build.h (FT2_ROOT, FT2_CONFIG_ROOT):
Removed. ANSI C doesn't (explicitly) allow macro expansion in
arguments using `##'.
(FT2_PUBLIC_FILE, FT2_CONFIG_FILE, FT2_INTERNAL_FILE): Use directory
names directly. Make them configurable. Use `##' to strip leading
and trailing spaces from arguments.
* builds/unix/ft2unix.h: Adapted.
* src/base/ftsystem.c (ft_alloc, ft_realloc, ft_free, ft_io_stream,
ft_close_stream): Use FT_CALLBACK_DEF.
* builds/unix/ftsystem.c: Use new header scheme.
(FT_Done_Memory): Use free() from FT_Memory structure.
* src/base/ftinit.c, src/base/ftmac.c: Header scheme fixes.
* include/freetype/config/ft2build.h (FT2_CONFIG_ROOT,
FT2_PUBLIC_FILE, FT2_CONFIG_FILE, FT2_INTERNAL_FILE,
FT_SOURCE_FILE): Use `##' operator to be really ANSI C compliant.
2000-12-12 23:28:12 +01:00
|
|
|
#include <ft2build.h>
|
2001-06-28 09:17:51 +02:00
|
|
|
/* we use our special ftconfig.h file, not the standard one */
|
2000-12-13 10:21:59 +01:00
|
|
|
#include <ftconfig.h>
|
* include/freetype/config/ft2build.h (FT2_ROOT, FT2_CONFIG_ROOT):
Removed. ANSI C doesn't (explicitly) allow macro expansion in
arguments using `##'.
(FT2_PUBLIC_FILE, FT2_CONFIG_FILE, FT2_INTERNAL_FILE): Use directory
names directly. Make them configurable. Use `##' to strip leading
and trailing spaces from arguments.
* builds/unix/ft2unix.h: Adapted.
* src/base/ftsystem.c (ft_alloc, ft_realloc, ft_free, ft_io_stream,
ft_close_stream): Use FT_CALLBACK_DEF.
* builds/unix/ftsystem.c: Use new header scheme.
(FT_Done_Memory): Use free() from FT_Memory structure.
* src/base/ftinit.c, src/base/ftmac.c: Header scheme fixes.
* include/freetype/config/ft2build.h (FT2_CONFIG_ROOT,
FT2_PUBLIC_FILE, FT2_CONFIG_FILE, FT2_INTERNAL_FILE,
FT_SOURCE_FILE): Use `##' operator to be really ANSI C compliant.
2000-12-12 23:28:12 +01:00
|
|
|
#include FT_INTERNAL_DEBUG_H
|
|
|
|
#include FT_SYSTEM_H
|
|
|
|
#include FT_ERRORS_H
|
2000-12-13 10:21:59 +01:00
|
|
|
#include FT_TYPES_H
|
|
|
|
#include FT_INTERNAL_OBJECTS_H
|
2000-07-08 02:22:20 +02:00
|
|
|
|
2000-08-01 00:51:00 +02:00
|
|
|
/* memory-mapping includes and definitions */
|
2000-07-08 02:22:20 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#ifndef MAP_FILE
|
|
|
|
#define MAP_FILE 0x00
|
|
|
|
#endif
|
|
|
|
|
2000-08-01 00:51:00 +02:00
|
|
|
#ifdef MUNMAP_USES_VOIDP
|
|
|
|
#define MUNMAP_ARG_CAST void *
|
|
|
|
#else
|
|
|
|
#define MUNMAP_ARG_CAST char *
|
2000-07-08 02:22:20 +02:00
|
|
|
#endif
|
|
|
|
|
2000-08-01 00:51:00 +02:00
|
|
|
#ifdef NEED_MUNMAP_DECL
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
#else
|
|
|
|
extern
|
|
|
|
#endif
|
2001-06-28 09:17:51 +02:00
|
|
|
int
|
|
|
|
munmap( char* addr,
|
|
|
|
int len );
|
2000-08-01 00:51:00 +02:00
|
|
|
|
|
|
|
#define MUNMAP_ARG_CAST char *
|
|
|
|
|
|
|
|
#endif /* NEED_DECLARATION_MUNMAP */
|
|
|
|
|
|
|
|
|
2000-12-13 10:21:59 +01:00
|
|
|
#include <sys/types.h>
|
2000-07-08 02:22:20 +02:00
|
|
|
#include <sys/stat.h>
|
2000-07-20 08:57:41 +02:00
|
|
|
|
2000-07-08 02:22:20 +02:00
|
|
|
#ifdef HAVE_FCNTL_H
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2004-02-16 10:38:05 +01:00
|
|
|
#include <errno.h>
|
2000-07-08 02:22:20 +02:00
|
|
|
|
|
|
|
|
2000-07-20 08:57:41 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* MEMORY MANAGEMENT INTERFACE */
|
|
|
|
/* */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* <Function> */
|
|
|
|
/* ft_alloc */
|
|
|
|
/* */
|
|
|
|
/* <Description> */
|
|
|
|
/* The memory allocation function. */
|
|
|
|
/* */
|
|
|
|
/* <Input> */
|
|
|
|
/* memory :: A pointer to the memory object. */
|
* include/freetype/config/ft2build.h (FT2_ROOT, FT2_CONFIG_ROOT):
Removed. ANSI C doesn't (explicitly) allow macro expansion in
arguments using `##'.
(FT2_PUBLIC_FILE, FT2_CONFIG_FILE, FT2_INTERNAL_FILE): Use directory
names directly. Make them configurable. Use `##' to strip leading
and trailing spaces from arguments.
* builds/unix/ft2unix.h: Adapted.
* src/base/ftsystem.c (ft_alloc, ft_realloc, ft_free, ft_io_stream,
ft_close_stream): Use FT_CALLBACK_DEF.
* builds/unix/ftsystem.c: Use new header scheme.
(FT_Done_Memory): Use free() from FT_Memory structure.
* src/base/ftinit.c, src/base/ftmac.c: Header scheme fixes.
* include/freetype/config/ft2build.h (FT2_CONFIG_ROOT,
FT2_PUBLIC_FILE, FT2_CONFIG_FILE, FT2_INTERNAL_FILE,
FT_SOURCE_FILE): Use `##' operator to be really ANSI C compliant.
2000-12-12 23:28:12 +01:00
|
|
|
/* */
|
2000-07-20 08:57:41 +02:00
|
|
|
/* size :: The requested size in bytes. */
|
|
|
|
/* */
|
|
|
|
/* <Return> */
|
* include/freetype/config/ft2build.h (FT2_ROOT, FT2_CONFIG_ROOT):
Removed. ANSI C doesn't (explicitly) allow macro expansion in
arguments using `##'.
(FT2_PUBLIC_FILE, FT2_CONFIG_FILE, FT2_INTERNAL_FILE): Use directory
names directly. Make them configurable. Use `##' to strip leading
and trailing spaces from arguments.
* builds/unix/ft2unix.h: Adapted.
* src/base/ftsystem.c (ft_alloc, ft_realloc, ft_free, ft_io_stream,
ft_close_stream): Use FT_CALLBACK_DEF.
* builds/unix/ftsystem.c: Use new header scheme.
(FT_Done_Memory): Use free() from FT_Memory structure.
* src/base/ftinit.c, src/base/ftmac.c: Header scheme fixes.
* include/freetype/config/ft2build.h (FT2_CONFIG_ROOT,
FT2_PUBLIC_FILE, FT2_CONFIG_FILE, FT2_INTERNAL_FILE,
FT_SOURCE_FILE): Use `##' operator to be really ANSI C compliant.
2000-12-12 23:28:12 +01:00
|
|
|
/* The address of newly allocated block. */
|
2000-07-20 08:57:41 +02:00
|
|
|
/* */
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_CALLBACK_DEF( void* )
|
2001-06-27 11:26:46 +02:00
|
|
|
ft_alloc( FT_Memory memory,
|
|
|
|
long size )
|
2000-07-08 02:22:20 +02:00
|
|
|
{
|
2000-07-20 08:57:41 +02:00
|
|
|
FT_UNUSED( memory );
|
2000-07-08 02:22:20 +02:00
|
|
|
|
2000-07-20 08:57:41 +02:00
|
|
|
return malloc( size );
|
|
|
|
}
|
2000-07-08 02:22:20 +02:00
|
|
|
|
|
|
|
|
2000-07-20 08:57:41 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* <Function> */
|
|
|
|
/* ft_realloc */
|
|
|
|
/* */
|
|
|
|
/* <Description> */
|
|
|
|
/* The memory reallocation function. */
|
|
|
|
/* */
|
|
|
|
/* <Input> */
|
|
|
|
/* memory :: A pointer to the memory object. */
|
|
|
|
/* */
|
|
|
|
/* cur_size :: The current size of the allocated memory block. */
|
|
|
|
/* */
|
|
|
|
/* new_size :: The newly requested size in bytes. */
|
|
|
|
/* */
|
|
|
|
/* block :: The current address of the block in memory. */
|
|
|
|
/* */
|
|
|
|
/* <Return> */
|
|
|
|
/* The address of the reallocated memory block. */
|
|
|
|
/* */
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_CALLBACK_DEF( void* )
|
2001-06-27 11:26:46 +02:00
|
|
|
ft_realloc( FT_Memory memory,
|
|
|
|
long cur_size,
|
|
|
|
long new_size,
|
|
|
|
void* block )
|
2000-07-08 02:22:20 +02:00
|
|
|
{
|
2000-07-20 08:57:41 +02:00
|
|
|
FT_UNUSED( memory );
|
|
|
|
FT_UNUSED( cur_size );
|
2000-07-08 02:22:20 +02:00
|
|
|
|
|
|
|
return realloc( block, new_size );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-20 08:57:41 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* <Function> */
|
|
|
|
/* ft_free */
|
|
|
|
/* */
|
|
|
|
/* <Description> */
|
|
|
|
/* The memory release function. */
|
|
|
|
/* */
|
|
|
|
/* <Input> */
|
2002-03-29 08:43:04 +01:00
|
|
|
/* memory :: A pointer to the memory object. */
|
2000-07-20 08:57:41 +02:00
|
|
|
/* */
|
2002-03-29 08:43:04 +01:00
|
|
|
/* block :: The address of block in memory to be freed. */
|
2000-07-20 08:57:41 +02:00
|
|
|
/* */
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_CALLBACK_DEF( void )
|
2001-06-27 11:26:46 +02:00
|
|
|
ft_free( FT_Memory memory,
|
|
|
|
void* block )
|
2000-07-08 02:22:20 +02:00
|
|
|
{
|
2000-07-20 08:57:41 +02:00
|
|
|
FT_UNUSED( memory );
|
|
|
|
|
2000-07-08 02:22:20 +02:00
|
|
|
free( block );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-20 08:57:41 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* RESOURCE MANAGEMENT INTERFACE */
|
|
|
|
/* */
|
|
|
|
/*************************************************************************/
|
2000-07-08 02:22:20 +02:00
|
|
|
|
|
|
|
|
2000-07-20 08:57:41 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
|
|
|
|
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
|
|
|
|
/* messages during execution. */
|
|
|
|
/* */
|
2000-07-08 02:22:20 +02:00
|
|
|
#undef FT_COMPONENT
|
|
|
|
#define FT_COMPONENT trace_io
|
|
|
|
|
2000-07-20 08:57:41 +02:00
|
|
|
/* We use the macro STREAM_FILE for convenience to extract the */
|
|
|
|
/* system-specific stream handle from a given FreeType stream object */
|
|
|
|
#define STREAM_FILE( stream ) ( (FILE*)stream->descriptor.pointer )
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* <Function> */
|
2004-02-16 10:38:05 +01:00
|
|
|
/* ft_close_stream_by_munmap */
|
2000-07-20 08:57:41 +02:00
|
|
|
/* */
|
|
|
|
/* <Description> */
|
2004-02-16 10:38:05 +01:00
|
|
|
/* The function to close a stream which is opened by mmap. */
|
2000-07-20 08:57:41 +02:00
|
|
|
/* */
|
|
|
|
/* <Input> */
|
|
|
|
/* stream :: A pointer to the stream object. */
|
|
|
|
/* */
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_CALLBACK_DEF( void )
|
2004-02-16 10:38:05 +01:00
|
|
|
ft_close_stream_by_munmap( FT_Stream stream )
|
2000-07-08 02:22:20 +02:00
|
|
|
{
|
2000-08-01 00:51:00 +02:00
|
|
|
munmap( (MUNMAP_ARG_CAST)stream->descriptor.pointer, stream->size );
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2000-07-08 02:22:20 +02:00
|
|
|
stream->descriptor.pointer = NULL;
|
|
|
|
stream->size = 0;
|
|
|
|
stream->base = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-16 10:38:05 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* <Function> */
|
|
|
|
/* ft_close_stream_by_free */
|
|
|
|
/* */
|
|
|
|
/* <Description> */
|
|
|
|
/* The function to close a stream which is created by ft_alloc. */
|
|
|
|
/* */
|
|
|
|
/* <Input> */
|
|
|
|
/* stream :: A pointer to the stream object. */
|
|
|
|
/* */
|
|
|
|
FT_CALLBACK_DEF( void )
|
|
|
|
ft_close_stream_by_free( FT_Stream stream )
|
|
|
|
{
|
|
|
|
ft_free( NULL, stream->descriptor.pointer );
|
|
|
|
|
|
|
|
stream->descriptor.pointer = NULL;
|
|
|
|
stream->size = 0;
|
|
|
|
stream->base = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
* include/freetype/config/ft2build.h (FT2_ROOT, FT2_CONFIG_ROOT):
Removed. ANSI C doesn't (explicitly) allow macro expansion in
arguments using `##'.
(FT2_PUBLIC_FILE, FT2_CONFIG_FILE, FT2_INTERNAL_FILE): Use directory
names directly. Make them configurable. Use `##' to strip leading
and trailing spaces from arguments.
* builds/unix/ft2unix.h: Adapted.
* src/base/ftsystem.c (ft_alloc, ft_realloc, ft_free, ft_io_stream,
ft_close_stream): Use FT_CALLBACK_DEF.
* builds/unix/ftsystem.c: Use new header scheme.
(FT_Done_Memory): Use free() from FT_Memory structure.
* src/base/ftinit.c, src/base/ftmac.c: Header scheme fixes.
* include/freetype/config/ft2build.h (FT2_CONFIG_ROOT,
FT2_PUBLIC_FILE, FT2_CONFIG_FILE, FT2_INTERNAL_FILE,
FT_SOURCE_FILE): Use `##' operator to be really ANSI C compliant.
2000-12-12 23:28:12 +01:00
|
|
|
/* documentation is in ftobjs.h */
|
|
|
|
|
2005-11-18 05:29:31 +01:00
|
|
|
FT_BASE_DEF( FT_Error )
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_Stream_Open( FT_Stream stream,
|
|
|
|
const char* filepathname )
|
2000-07-08 02:22:20 +02:00
|
|
|
{
|
|
|
|
int file;
|
|
|
|
struct stat stat_buf;
|
|
|
|
|
2000-07-20 08:57:41 +02:00
|
|
|
|
|
|
|
if ( !stream )
|
|
|
|
return FT_Err_Invalid_Stream_Handle;
|
|
|
|
|
2000-07-08 02:22:20 +02:00
|
|
|
/* open the file */
|
|
|
|
file = open( filepathname, O_RDONLY );
|
2000-07-20 08:57:41 +02:00
|
|
|
if ( file < 0 )
|
2000-07-08 02:22:20 +02:00
|
|
|
{
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_ERROR(( "FT_Stream_Open:" ));
|
2000-07-08 02:22:20 +02:00
|
|
|
FT_ERROR(( " could not open `%s'\n", filepathname ));
|
2000-07-20 08:57:41 +02:00
|
|
|
return FT_Err_Cannot_Open_Resource;
|
2000-07-08 02:22:20 +02:00
|
|
|
}
|
|
|
|
|
2002-01-03 23:06:13 +01:00
|
|
|
/* Here we ensure that a "fork" will _not_ duplicate */
|
|
|
|
/* our opened input streams on Unix. This is critical */
|
|
|
|
/* since it avoids some (possible) access control */
|
|
|
|
/* issues and cleans up the kernel file table a bit. */
|
2002-01-03 18:08:20 +01:00
|
|
|
/* */
|
|
|
|
#ifdef F_SETFD
|
2002-01-03 23:06:13 +01:00
|
|
|
#ifdef FD_CLOEXEC
|
2002-03-29 08:43:04 +01:00
|
|
|
(void)fcntl( file, F_SETFD, FD_CLOEXEC );
|
2002-01-03 23:06:13 +01:00
|
|
|
#else
|
2002-03-29 08:43:04 +01:00
|
|
|
(void)fcntl( file, F_SETFD, 1 );
|
2002-01-03 23:06:13 +01:00
|
|
|
#endif /* FD_CLOEXEC */
|
2002-01-03 18:08:20 +01:00
|
|
|
#endif /* F_SETFD */
|
|
|
|
|
2000-07-20 08:57:41 +02:00
|
|
|
if ( fstat( file, &stat_buf ) < 0 )
|
2000-07-08 02:22:20 +02:00
|
|
|
{
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_ERROR(( "FT_Stream_Open:" ));
|
2000-07-08 02:22:20 +02:00
|
|
|
FT_ERROR(( " could not `fstat' file `%s'\n", filepathname ));
|
|
|
|
goto Fail_Map;
|
|
|
|
}
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2000-07-20 08:57:41 +02:00
|
|
|
stream->size = stat_buf.st_size;
|
|
|
|
stream->pos = 0;
|
2000-08-01 00:51:00 +02:00
|
|
|
stream->base = (unsigned char *)mmap( NULL,
|
|
|
|
stream->size,
|
|
|
|
PROT_READ,
|
|
|
|
MAP_FILE | MAP_PRIVATE,
|
|
|
|
file,
|
|
|
|
0 );
|
2000-07-08 02:22:20 +02:00
|
|
|
|
2004-02-16 10:38:05 +01:00
|
|
|
if ( (long)stream->base != -1 )
|
|
|
|
stream->close = ft_close_stream_by_munmap;
|
|
|
|
else
|
2000-07-08 02:22:20 +02:00
|
|
|
{
|
2004-02-16 10:38:05 +01:00
|
|
|
ssize_t total_read_count;
|
2005-10-28 18:14:14 +02:00
|
|
|
|
2004-02-16 10:38:05 +01:00
|
|
|
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_ERROR(( "FT_Stream_Open:" ));
|
2000-07-20 08:57:41 +02:00
|
|
|
FT_ERROR(( " could not `mmap' file `%s'\n", filepathname ));
|
2005-10-28 18:14:14 +02:00
|
|
|
|
2004-12-29 00:08:51 +01:00
|
|
|
stream->base = (unsigned char*)ft_alloc( NULL, stream->size );
|
2005-10-28 18:14:14 +02:00
|
|
|
|
2004-02-16 10:38:05 +01:00
|
|
|
if ( !stream->base )
|
|
|
|
{
|
|
|
|
FT_ERROR(( "FT_Stream_Open:" ));
|
|
|
|
FT_ERROR(( " could not `alloc' memory\n" ));
|
|
|
|
goto Fail_Map;
|
|
|
|
}
|
2005-10-28 18:14:14 +02:00
|
|
|
|
2004-02-16 10:38:05 +01:00
|
|
|
total_read_count = 0;
|
|
|
|
do {
|
|
|
|
ssize_t read_count;
|
|
|
|
|
|
|
|
|
2005-10-28 18:14:14 +02:00
|
|
|
read_count = read( file,
|
|
|
|
stream->base + total_read_count,
|
2004-02-16 10:38:05 +01:00
|
|
|
stream->size - total_read_count );
|
|
|
|
|
|
|
|
if ( ( read_count == -1 ) )
|
|
|
|
{
|
|
|
|
if ( errno == EINTR )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
FT_ERROR(( "FT_Stream_Open:" ));
|
|
|
|
FT_ERROR(( " error while `read'ing file `%s'\n", filepathname ));
|
|
|
|
goto Fail_Read;
|
|
|
|
}
|
|
|
|
|
|
|
|
total_read_count += read_count;
|
|
|
|
|
2004-12-29 00:08:51 +01:00
|
|
|
} while ( (unsigned long)total_read_count != stream->size );
|
2004-02-16 10:38:05 +01:00
|
|
|
|
|
|
|
stream->close = ft_close_stream_by_free;
|
2000-07-08 02:22:20 +02:00
|
|
|
}
|
|
|
|
|
2000-07-20 08:57:41 +02:00
|
|
|
close( file );
|
2000-07-08 02:22:20 +02:00
|
|
|
|
|
|
|
stream->descriptor.pointer = stream->base;
|
|
|
|
stream->pathname.pointer = (char*)filepathname;
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2004-02-16 10:38:05 +01:00
|
|
|
stream->read = 0;
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_TRACE1(( "FT_Stream_Open:" ));
|
2000-07-08 02:22:20 +02:00
|
|
|
FT_TRACE1(( " opened `%s' (%d bytes) successfully\n",
|
|
|
|
filepathname, stream->size ));
|
|
|
|
|
|
|
|
return FT_Err_Ok;
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2004-02-16 10:38:05 +01:00
|
|
|
Fail_Read:
|
|
|
|
ft_free( NULL, stream->base );
|
|
|
|
|
2000-07-08 02:22:20 +02:00
|
|
|
Fail_Map:
|
2000-07-20 08:57:41 +02:00
|
|
|
close( file );
|
|
|
|
|
|
|
|
stream->base = NULL;
|
|
|
|
stream->size = 0;
|
|
|
|
stream->pos = 0;
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2000-07-08 02:22:20 +02:00
|
|
|
return FT_Err_Cannot_Open_Stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-24 09:32:55 +02:00
|
|
|
#ifdef FT_DEBUG_MEMORY
|
|
|
|
|
|
|
|
extern FT_Int
|
|
|
|
ft_mem_debug_init( FT_Memory memory );
|
2002-02-24 06:26:57 +01:00
|
|
|
|
2001-10-24 09:32:55 +02:00
|
|
|
extern void
|
|
|
|
ft_mem_debug_done( FT_Memory memory );
|
2002-02-24 06:26:57 +01:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2001-10-24 09:32:55 +02:00
|
|
|
|
* include/freetype/config/ft2build.h (FT2_ROOT, FT2_CONFIG_ROOT):
Removed. ANSI C doesn't (explicitly) allow macro expansion in
arguments using `##'.
(FT2_PUBLIC_FILE, FT2_CONFIG_FILE, FT2_INTERNAL_FILE): Use directory
names directly. Make them configurable. Use `##' to strip leading
and trailing spaces from arguments.
* builds/unix/ft2unix.h: Adapted.
* src/base/ftsystem.c (ft_alloc, ft_realloc, ft_free, ft_io_stream,
ft_close_stream): Use FT_CALLBACK_DEF.
* builds/unix/ftsystem.c: Use new header scheme.
(FT_Done_Memory): Use free() from FT_Memory structure.
* src/base/ftinit.c, src/base/ftmac.c: Header scheme fixes.
* include/freetype/config/ft2build.h (FT2_CONFIG_ROOT,
FT2_PUBLIC_FILE, FT2_CONFIG_FILE, FT2_INTERNAL_FILE,
FT_SOURCE_FILE): Use `##' operator to be really ANSI C compliant.
2000-12-12 23:28:12 +01:00
|
|
|
/* documentation is in ftobjs.h */
|
|
|
|
|
2005-11-18 05:29:31 +01:00
|
|
|
FT_BASE_DEF( FT_Memory )
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_New_Memory( void )
|
2000-07-08 02:22:20 +02:00
|
|
|
{
|
|
|
|
FT_Memory memory;
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2000-07-20 08:57:41 +02:00
|
|
|
|
|
|
|
memory = (FT_Memory)malloc( sizeof ( *memory ) );
|
|
|
|
if ( memory )
|
2001-10-24 16:43:40 +02:00
|
|
|
{
|
2000-07-08 02:22:20 +02:00
|
|
|
memory->user = 0;
|
|
|
|
memory->alloc = ft_alloc;
|
|
|
|
memory->realloc = ft_realloc;
|
|
|
|
memory->free = ft_free;
|
2001-10-24 09:32:55 +02:00
|
|
|
#ifdef FT_DEBUG_MEMORY
|
|
|
|
ft_mem_debug_init( memory );
|
2002-02-24 06:26:57 +01:00
|
|
|
#endif
|
2000-07-08 02:22:20 +02:00
|
|
|
}
|
2000-07-20 08:57:41 +02:00
|
|
|
|
2000-07-08 02:22:20 +02:00
|
|
|
return memory;
|
|
|
|
}
|
|
|
|
|
2000-07-28 01:29:08 +02:00
|
|
|
|
* include/freetype/config/ft2build.h (FT2_ROOT, FT2_CONFIG_ROOT):
Removed. ANSI C doesn't (explicitly) allow macro expansion in
arguments using `##'.
(FT2_PUBLIC_FILE, FT2_CONFIG_FILE, FT2_INTERNAL_FILE): Use directory
names directly. Make them configurable. Use `##' to strip leading
and trailing spaces from arguments.
* builds/unix/ft2unix.h: Adapted.
* src/base/ftsystem.c (ft_alloc, ft_realloc, ft_free, ft_io_stream,
ft_close_stream): Use FT_CALLBACK_DEF.
* builds/unix/ftsystem.c: Use new header scheme.
(FT_Done_Memory): Use free() from FT_Memory structure.
* src/base/ftinit.c, src/base/ftmac.c: Header scheme fixes.
* include/freetype/config/ft2build.h (FT2_CONFIG_ROOT,
FT2_PUBLIC_FILE, FT2_CONFIG_FILE, FT2_INTERNAL_FILE,
FT_SOURCE_FILE): Use `##' operator to be really ANSI C compliant.
2000-12-12 23:28:12 +01:00
|
|
|
/* documentation is in ftobjs.h */
|
|
|
|
|
2005-11-18 05:29:31 +01:00
|
|
|
FT_BASE_DEF( void )
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_Done_Memory( FT_Memory memory )
|
2000-07-27 23:40:22 +02:00
|
|
|
{
|
2001-10-24 09:32:55 +02:00
|
|
|
#ifdef FT_DEBUG_MEMORY
|
|
|
|
ft_mem_debug_done( memory );
|
2002-02-24 06:26:57 +01:00
|
|
|
#endif
|
* include/freetype/config/ft2build.h (FT2_ROOT, FT2_CONFIG_ROOT):
Removed. ANSI C doesn't (explicitly) allow macro expansion in
arguments using `##'.
(FT2_PUBLIC_FILE, FT2_CONFIG_FILE, FT2_INTERNAL_FILE): Use directory
names directly. Make them configurable. Use `##' to strip leading
and trailing spaces from arguments.
* builds/unix/ft2unix.h: Adapted.
* src/base/ftsystem.c (ft_alloc, ft_realloc, ft_free, ft_io_stream,
ft_close_stream): Use FT_CALLBACK_DEF.
* builds/unix/ftsystem.c: Use new header scheme.
(FT_Done_Memory): Use free() from FT_Memory structure.
* src/base/ftinit.c, src/base/ftmac.c: Header scheme fixes.
* include/freetype/config/ft2build.h (FT2_CONFIG_ROOT,
FT2_PUBLIC_FILE, FT2_CONFIG_FILE, FT2_INTERNAL_FILE,
FT_SOURCE_FILE): Use `##' operator to be really ANSI C compliant.
2000-12-12 23:28:12 +01:00
|
|
|
memory->free( memory, memory );
|
2000-07-27 23:40:22 +02:00
|
|
|
}
|
|
|
|
|
2000-07-20 08:57:41 +02:00
|
|
|
|
|
|
|
/* END */
|