2000-07-20 08:57:41 +02:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* ftsystem.c */
|
|
|
|
/* */
|
|
|
|
/* Unix-specific FreeType low-level system interface (body). */
|
|
|
|
/* */
|
2019-02-23 10:07:09 +01:00
|
|
|
/* Copyright (C) 1996-2019 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
|
* builds/unix/ftsystem.c, include/freetype/config/ftheader.h,
include/freetype/internal/services/svotval.h,
include/freetype/internal/services/svpfr.h,
src/base/ftsystem.c, src/bdf/bdfdrivr.c, src/cache/ftcbasic.c,
src/cff/cffcmap.c, src/gzip/ftgzip.c, src/lzw/ftlzw.c,
src/lzw/ftlzw2.c, src/psaux/t1cmap.c, src/sfnt/ttbdf.c,
src/smooth/ftgrays.c:
solved -Wmissing-prototypes warnings with GCC
2006-02-25 15:53:02 +01:00
|
|
|
#include FT_INTERNAL_STREAM_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,
|
2018-10-27 04:52:25 +02:00
|
|
|
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,
|
2018-10-27 04:52:25 +02:00
|
|
|
long cur_size,
|
|
|
|
long new_size,
|
2001-06-27 11:26:46 +02:00
|
|
|
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
|
2018-08-16 05:55:18 +02:00
|
|
|
#define FT_COMPONENT io
|
2000-07-08 02:22:20 +02:00
|
|
|
|
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 )
|
2013-05-17 17:40:27 +02:00
|
|
|
return FT_THROW( Invalid_Stream_Handle );
|
2000-07-20 08:57:41 +02:00
|
|
|
|
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 ));
|
2013-05-17 17:40:27 +02:00
|
|
|
return FT_THROW( 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
|
|
|
|
2007-03-22 06:23:53 +01:00
|
|
|
/* XXX: TODO -- real 64bit platform support */
|
2007-03-22 07:12:43 +01:00
|
|
|
/* */
|
2013-11-13 08:55:46 +01:00
|
|
|
/* `stream->size' is typedef'd to unsigned long (in `ftsystem.h'); */
|
|
|
|
/* `stat_buf.st_size', however, is usually typedef'd to off_t */
|
|
|
|
/* (in sys/stat.h). */
|
2007-03-22 06:23:53 +01:00
|
|
|
/* On some platforms, the former is 32bit and the latter is 64bit. */
|
2007-03-22 07:12:43 +01:00
|
|
|
/* To avoid overflow caused by fonts in huge files larger than */
|
|
|
|
/* 2GB, do a test. Temporary fix proposed by Sean McBride. */
|
2007-03-22 06:23:53 +01:00
|
|
|
/* */
|
2007-06-01 08:49:03 +02:00
|
|
|
if ( stat_buf.st_size > LONG_MAX )
|
2007-03-22 06:23:53 +01:00
|
|
|
{
|
2009-01-22 05:00:32 +01:00
|
|
|
FT_ERROR(( "FT_Stream_Open: file is too big\n" ));
|
2007-03-22 06:23:53 +01:00
|
|
|
goto Fail_Map;
|
|
|
|
}
|
2008-12-22 19:09:48 +01:00
|
|
|
else if ( stat_buf.st_size == 0 )
|
|
|
|
{
|
2009-01-22 05:00:32 +01:00
|
|
|
FT_ERROR(( "FT_Stream_Open: zero-length file\n" ));
|
2008-12-22 19:09:48 +01:00
|
|
|
goto Fail_Map;
|
|
|
|
}
|
2007-03-22 06:23:53 +01:00
|
|
|
|
|
|
|
/* This cast potentially truncates a 64bit to 32bit! */
|
|
|
|
stream->size = (unsigned long)stat_buf.st_size;
|
2000-07-20 08:57:41 +02:00
|
|
|
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
|
|
|
|
2007-05-04 08:13:46 +02:00
|
|
|
/* on some RTOS, mmap might return 0 */
|
|
|
|
if ( (long)stream->base != -1 && stream->base != NULL )
|
2004-02-16 10:38:05 +01:00
|
|
|
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;
|
2013-12-02 09:52:38 +01:00
|
|
|
do
|
|
|
|
{
|
2004-02-16 10:38:05 +01:00
|
|
|
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 );
|
|
|
|
|
2006-05-11 05:01:42 +02:00
|
|
|
if ( read_count <= 0 )
|
2004-02-16 10:38:05 +01:00
|
|
|
{
|
2006-05-11 05:01:42 +02:00
|
|
|
if ( read_count == -1 && errno == EINTR )
|
2004-02-16 10:38:05 +01:00
|
|
|
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
|
|
|
|
2013-05-17 17:40:27 +02:00
|
|
|
return FT_THROW( Cannot_Open_Stream );
|
2000-07-08 02:22:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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 */
|