builds/{unix,windows}/ftsystem.c: Sync comments with `src/base/ftsystem.c`.

Also some minor code formatting.
This commit is contained in:
Werner Lemberg 2021-02-02 09:38:25 +01:00
parent 4554c6da42
commit 689402418f
2 changed files with 256 additions and 217 deletions

View File

@ -1,19 +1,19 @@
/***************************************************************************/ /****************************************************************************
/* */ *
/* ftsystem.c */ * ftsystem.c
/* */ *
/* Unix-specific FreeType low-level system interface (body). */ * Unix-specific FreeType low-level system interface (body).
/* */ *
/* Copyright (C) 1996-2021 by */ * Copyright (C) 1996-2021 by
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ * David Turner, Robert Wilhelm, and Werner Lemberg.
/* */ *
/* This file is part of the FreeType project, and may only be used, */ * This file is part of the FreeType project, and may only be used,
/* modified, and distributed under the terms of the FreeType project */ * modified, and distributed under the terms of the FreeType project
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ * license, LICENSE.TXT. By continuing to use, modify, or distribute
/* this file you indicate that you have read the license and */ * this file you indicate that you have read the license and
/* understand and accept it fully. */ * understand and accept it fully.
/* */ *
/***************************************************************************/ */
#include <ft2build.h> #include <ft2build.h>
@ -70,29 +70,40 @@
#include <errno.h> #include <errno.h>
/*************************************************************************/ /**************************************************************************
/* */ *
/* MEMORY MANAGEMENT INTERFACE */ * MEMORY MANAGEMENT INTERFACE
/* */ *
/*************************************************************************/ */
/*************************************************************************/ /**************************************************************************
/* */ *
/* <Function> */ * It is not necessary to do any error checking for the
/* ft_alloc */ * allocation-related functions. This will be done by the higher level
/* */ * routines like ft_mem_alloc() or ft_mem_realloc().
/* <Description> */ *
/* The memory allocation function. */ */
/* */
/* <Input> */
/* memory :: A pointer to the memory object. */ /**************************************************************************
/* */ *
/* size :: The requested size in bytes. */ * @Function:
/* */ * ft_alloc
/* <Return> */ *
/* The address of newly allocated block. */ * @Description:
/* */ * The memory allocation function.
*
* @Input:
* memory ::
* A pointer to the memory object.
*
* size ::
* The requested size in bytes.
*
* @Return:
* The address of newly allocated block.
*/
FT_CALLBACK_DEF( void* ) FT_CALLBACK_DEF( void* )
ft_alloc( FT_Memory memory, ft_alloc( FT_Memory memory,
long size ) long size )
@ -103,26 +114,30 @@
} }
/*************************************************************************/ /**************************************************************************
/* */ *
/* <Function> */ * @Function:
/* ft_realloc */ * ft_realloc
/* */ *
/* <Description> */ * @Description:
/* The memory reallocation function. */ * The memory reallocation function.
/* */ *
/* <Input> */ * @Input:
/* memory :: A pointer to the memory object. */ * memory ::
/* */ * A pointer to the memory object.
/* cur_size :: The current size of the allocated memory block. */ *
/* */ * cur_size ::
/* new_size :: The newly requested size in bytes. */ * The current size of the allocated memory block.
/* */ *
/* block :: The current address of the block in memory. */ * new_size ::
/* */ * The newly requested size in bytes.
/* <Return> */ *
/* The address of the reallocated memory block. */ * block ::
/* */ * The current address of the block in memory.
*
* @Return:
* The address of the reallocated memory block.
*/
FT_CALLBACK_DEF( void* ) FT_CALLBACK_DEF( void* )
ft_realloc( FT_Memory memory, ft_realloc( FT_Memory memory,
long cur_size, long cur_size,
@ -136,19 +151,21 @@
} }
/*************************************************************************/ /**************************************************************************
/* */ *
/* <Function> */ * @Function:
/* ft_free */ * ft_free
/* */ *
/* <Description> */ * @Description:
/* The memory release function. */ * The memory release function.
/* */ *
/* <Input> */ * @Input:
/* memory :: A pointer to the memory object. */ * memory ::
/* */ * A pointer to the memory object.
/* block :: The address of block in memory to be freed. */ *
/* */ * block ::
* The address of block in memory to be freed.
*/
FT_CALLBACK_DEF( void ) FT_CALLBACK_DEF( void )
ft_free( FT_Memory memory, ft_free( FT_Memory memory,
void* block ) void* block )
@ -159,19 +176,19 @@
} }
/*************************************************************************/ /**************************************************************************
/* */ *
/* RESOURCE MANAGEMENT INTERFACE */ * RESOURCE MANAGEMENT INTERFACE
/* */ *
/*************************************************************************/ */
/*************************************************************************/ /**************************************************************************
/* */ *
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ * 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 */ * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
/* messages during execution. */ * messages during execution.
/* */ */
#undef FT_COMPONENT #undef FT_COMPONENT
#define FT_COMPONENT io #define FT_COMPONENT io
@ -180,17 +197,17 @@
#define STREAM_FILE( stream ) ( (FILE*)stream->descriptor.pointer ) #define STREAM_FILE( stream ) ( (FILE*)stream->descriptor.pointer )
/*************************************************************************/ /**************************************************************************
/* */ *
/* <Function> */ * @Function:
/* ft_close_stream_by_munmap */ * ft_close_stream_by_munmap
/* */ *
/* <Description> */ * @Description:
/* The function to close a stream which is opened by mmap. */ * The function to close a stream which is opened by mmap.
/* */ *
/* <Input> */ * @Input:
/* stream :: A pointer to the stream object. */ * stream :: A pointer to the stream object.
/* */ */
FT_CALLBACK_DEF( void ) FT_CALLBACK_DEF( void )
ft_close_stream_by_munmap( FT_Stream stream ) ft_close_stream_by_munmap( FT_Stream stream )
{ {
@ -202,17 +219,17 @@
} }
/*************************************************************************/ /**************************************************************************
/* */ *
/* <Function> */ * @Function:
/* ft_close_stream_by_free */ * ft_close_stream_by_free
/* */ *
/* <Description> */ * @Description:
/* The function to close a stream which is created by ft_alloc. */ * The function to close a stream which is created by ft_alloc.
/* */ *
/* <Input> */ * @Input:
/* stream :: A pointer to the stream object. */ * stream :: A pointer to the stream object.
/* */ */
FT_CALLBACK_DEF( void ) FT_CALLBACK_DEF( void )
ft_close_stream_by_free( FT_Stream stream ) ft_close_stream_by_free( FT_Stream stream )
{ {

View File

@ -1,19 +1,19 @@
/***************************************************************************/ /****************************************************************************
/* */ *
/* ftsystem.c */ * ftsystem.c
/* */ *
/* Unix-specific FreeType low-level system interface (body). */ * Windows-specific FreeType low-level system interface (body).
/* */ *
/* Copyright (C) 1996-2020 by */ * Copyright (C) 2021 by
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ * David Turner, Robert Wilhelm, and Werner Lemberg.
/* */ *
/* This file is part of the FreeType project, and may only be used, */ * This file is part of the FreeType project, and may only be used,
/* modified, and distributed under the terms of the FreeType project */ * modified, and distributed under the terms of the FreeType project
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ * license, LICENSE.TXT. By continuing to use, modify, or distribute
/* this file you indicate that you have read the license and */ * this file you indicate that you have read the license and
/* understand and accept it fully. */ * understand and accept it fully.
/* */ *
/***************************************************************************/ */
#include <ft2build.h> #include <ft2build.h>
@ -31,29 +31,40 @@
#include <stdlib.h> #include <stdlib.h>
/*************************************************************************/ /**************************************************************************
/* */ *
/* MEMORY MANAGEMENT INTERFACE */ * MEMORY MANAGEMENT INTERFACE
/* */ *
/*************************************************************************/ */
/*************************************************************************/ /**************************************************************************
/* */ *
/* <Function> */ * It is not necessary to do any error checking for the
/* ft_alloc */ * allocation-related functions. This will be done by the higher level
/* */ * routines like ft_mem_alloc() or ft_mem_realloc().
/* <Description> */ *
/* The memory allocation function. */ */
/* */
/* <Input> */
/* memory :: A pointer to the memory object. */ /**************************************************************************
/* */ *
/* size :: The requested size in bytes. */ * @Function:
/* */ * ft_alloc
/* <Return> */ *
/* The address of newly allocated block. */ * @Description:
/* */ * The memory allocation function.
*
* @Input:
* memory ::
* A pointer to the memory object.
*
* size ::
* The requested size in bytes.
*
* @Return:
* The address of newly allocated block.
*/
FT_CALLBACK_DEF( void* ) FT_CALLBACK_DEF( void* )
ft_alloc( FT_Memory memory, ft_alloc( FT_Memory memory,
long size ) long size )
@ -64,26 +75,30 @@
} }
/*************************************************************************/ /**************************************************************************
/* */ *
/* <Function> */ * @Function:
/* ft_realloc */ * ft_realloc
/* */ *
/* <Description> */ * @Description:
/* The memory reallocation function. */ * The memory reallocation function.
/* */ *
/* <Input> */ * @Input:
/* memory :: A pointer to the memory object. */ * memory ::
/* */ * A pointer to the memory object.
/* cur_size :: The current size of the allocated memory block. */ *
/* */ * cur_size ::
/* new_size :: The newly requested size in bytes. */ * The current size of the allocated memory block.
/* */ *
/* block :: The current address of the block in memory. */ * new_size ::
/* */ * The newly requested size in bytes.
/* <Return> */ *
/* The address of the reallocated memory block. */ * block ::
/* */ * The current address of the block in memory.
*
* @Return:
* The address of the reallocated memory block.
*/
FT_CALLBACK_DEF( void* ) FT_CALLBACK_DEF( void* )
ft_realloc( FT_Memory memory, ft_realloc( FT_Memory memory,
long cur_size, long cur_size,
@ -97,19 +112,21 @@
} }
/*************************************************************************/ /**************************************************************************
/* */ *
/* <Function> */ * @Function:
/* ft_free */ * ft_free
/* */ *
/* <Description> */ * @Description:
/* The memory release function. */ * The memory release function.
/* */ *
/* <Input> */ * @Input:
/* memory :: A pointer to the memory object. */ * memory ::
/* */ * A pointer to the memory object.
/* block :: The address of block in memory to be freed. */ *
/* */ * block ::
* The address of block in memory to be freed.
*/
FT_CALLBACK_DEF( void ) FT_CALLBACK_DEF( void )
ft_free( FT_Memory memory, ft_free( FT_Memory memory,
void* block ) void* block )
@ -120,19 +137,19 @@
} }
/*************************************************************************/ /**************************************************************************
/* */ *
/* RESOURCE MANAGEMENT INTERFACE */ * RESOURCE MANAGEMENT INTERFACE
/* */ *
/*************************************************************************/ */
/*************************************************************************/ /**************************************************************************
/* */ *
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ * 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 */ * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
/* messages during execution. */ * messages during execution.
/* */ */
#undef FT_COMPONENT #undef FT_COMPONENT
#define FT_COMPONENT io #define FT_COMPONENT io
@ -141,17 +158,17 @@
#define STREAM_FILE( stream ) ( (FILE*)stream->descriptor.pointer ) #define STREAM_FILE( stream ) ( (FILE*)stream->descriptor.pointer )
/*************************************************************************/ /**************************************************************************
/* */ *
/* <Function> */ * @Function:
/* ft_close_stream_by_munmap */ * ft_close_stream_by_munmap
/* */ *
/* <Description> */ * @Description:
/* The function to close a stream which is opened by mmap. */ * The function to close a stream which is opened by mmap.
/* */ *
/* <Input> */ * @Input:
/* stream :: A pointer to the stream object. */ * stream :: A pointer to the stream object.
/* */ */
FT_CALLBACK_DEF( void ) FT_CALLBACK_DEF( void )
ft_close_stream_by_munmap( FT_Stream stream ) ft_close_stream_by_munmap( FT_Stream stream )
{ {
@ -163,17 +180,17 @@
} }
/*************************************************************************/ /**************************************************************************
/* */ *
/* <Function> */ * @Function:
/* ft_close_stream_by_free */ * ft_close_stream_by_free
/* */ *
/* <Description> */ * @Description:
/* The function to close a stream which is created by ft_alloc. */ * The function to close a stream which is created by ft_alloc.
/* */ *
/* <Input> */ * @Input:
/* stream :: A pointer to the stream object. */ * stream :: A pointer to the stream object.
/* */ */
FT_CALLBACK_DEF( void ) FT_CALLBACK_DEF( void )
ft_close_stream_by_free( FT_Stream stream ) ft_close_stream_by_free( FT_Stream stream )
{ {
@ -191,9 +208,10 @@
FT_Stream_Open( FT_Stream stream, FT_Stream_Open( FT_Stream stream,
const char* filepathname ) const char* filepathname )
{ {
HANDLE file; HANDLE file;
HANDLE fm; HANDLE fm;
LARGE_INTEGER size; LARGE_INTEGER size;
if ( !stream ) if ( !stream )
return FT_THROW( Invalid_Stream_Handle ); return FT_THROW( Invalid_Stream_Handle );
@ -201,14 +219,14 @@
/* open the file */ /* open the file */
file = CreateFileA( filepathname, GENERIC_READ, FILE_SHARE_READ, NULL, file = CreateFileA( filepathname, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 ); OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
if (file == INVALID_HANDLE_VALUE) if ( file == INVALID_HANDLE_VALUE )
{ {
FT_ERROR(( "FT_Stream_Open:" )); FT_ERROR(( "FT_Stream_Open:" ));
FT_ERROR(( " could not open `%s'\n", filepathname )); FT_ERROR(( " could not open `%s'\n", filepathname ));
return FT_THROW( Cannot_Open_Resource ); return FT_THROW( Cannot_Open_Resource );
} }
if ( GetFileSizeEx(file, &size) == FALSE ) if ( GetFileSizeEx( file, &size ) == FALSE )
{ {
FT_ERROR(( "FT_Stream_Open:" )); FT_ERROR(( "FT_Stream_Open:" ));
FT_ERROR(( " could not retrieve size of file `%s'\n", filepathname )); FT_ERROR(( " could not retrieve size of file `%s'\n", filepathname ));
@ -229,8 +247,8 @@
goto Fail_Open; goto Fail_Open;
} }
fm = CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL); fm = CreateFileMapping( file, NULL, PAGE_READONLY, 0, 0, NULL );
if (fm == NULL) if ( fm == NULL )
{ {
FT_ERROR(( "FT_Stream_Open: can not map file\n" )); FT_ERROR(( "FT_Stream_Open: can not map file\n" ));
goto Fail_Open; goto Fail_Open;
@ -241,14 +259,17 @@
/* a size greater than LONG_MAX */ /* a size greater than LONG_MAX */
stream->size = size.LowPart; stream->size = size.LowPart;
stream->pos = 0; stream->pos = 0;
stream->base = (unsigned char *)MapViewOfFile(fm, FILE_MAP_READ, 0, 0, 0); stream->base = (unsigned char *)
MapViewOfFile( fm, FILE_MAP_READ, 0, 0, 0 );
CloseHandle( fm );
CloseHandle(fm);
if ( stream->base != NULL ) if ( stream->base != NULL )
stream->close = ft_close_stream_by_munmap; stream->close = ft_close_stream_by_munmap;
else else
{ {
DWORD total_read_count; DWORD total_read_count;
FT_ERROR(( "FT_Stream_Open:" )); FT_ERROR(( "FT_Stream_Open:" ));
FT_ERROR(( " could not `mmap' file `%s'\n", filepathname )); FT_ERROR(( " could not `mmap' file `%s'\n", filepathname ));
@ -265,7 +286,8 @@
total_read_count = 0; total_read_count = 0;
do do
{ {
DWORD read_count; DWORD read_count;
if ( ReadFile( file, if ( ReadFile( file,
stream->base + total_read_count, stream->base + total_read_count,