void get_elf_info(t_env *e) { Elf64_Ehdr *file_header; file_header = (Elf64_Ehdr *)e->file; if (ft_memcmp(file_header->e_ident, ELFMAG, SELFMAG)) ft_fatal("Invalid ELF file type.", e); if (file_header->e_ident[EI_CLASS] != ELFCLASS64 && file_header->e_ident[EI_CLASS] != ELFCLASS32) ft_fatal("Unsupported ELF file class.", e); if (file_header->e_ident[EI_DATA] == ELFDATANONE) ft_fatal("Unsupported ELF file byte order.", e); if (file_header->e_ident[EI_VERSION] != EV_CURRENT) ft_fatal("Unsupported ELF file version.", e); if (file_header->e_type != ET_EXEC && file_header->e_type != ET_DYN) ft_fatal("Unsupported ELF file type.", e); if (file_header->e_version != EV_CURRENT) ft_fatal("Unsupported ELF file version.", e); generate_new_key(e->key); if (file_header->e_ident[EI_CLASS] == ELFCLASS64) pack_elf64(e); /* if (file_header->e_ident[EI_CLASS] == ELFCLASS32) */ /* pack_elf32(e); */ }
static FT_Error check_type1_format( FT_Stream stream, const char* header_string, size_t header_length ) { FT_Error error; FT_UShort tag; FT_ULong dummy; if ( FT_STREAM_SEEK( 0 ) ) goto Exit; error = read_pfb_tag( stream, &tag, &dummy ); if ( error ) goto Exit; /* We assume that the first segment in a PFB is always encoded as */ /* text. This might be wrong (and the specification doesn't insist */ /* on that), but we have never seen a counterexample. */ if ( tag != 0x8001U && FT_STREAM_SEEK( 0 ) ) goto Exit; if ( !FT_FRAME_ENTER( header_length ) ) { error = T1_Err_Ok; if ( ft_memcmp( stream->cursor, header_string, header_length ) != 0 ) error = T1_Err_Unknown_File_Format; FT_FRAME_EXIT(); } Exit: return error; }
t42_parser_init( T42_Parser parser, FT_Stream stream, FT_Memory memory, PSAux_Service psaux ) { FT_Error error = FT_Err_Ok; FT_Long size; psaux->ps_parser_funcs->init( &parser->root, 0, 0, memory ); parser->stream = stream; parser->base_len = 0; parser->base_dict = 0; parser->in_memory = 0; /*******************************************************************/ /* */ /* Here a short summary of what is going on: */ /* */ /* When creating a new Type 42 parser, we try to locate and load */ /* the base dictionary, loading the whole font into memory. */ /* */ /* When `loading' the base dictionary, we only set up pointers */ /* in the case of a memory-based stream. Otherwise, we allocate */ /* and load the base dictionary in it. */ /* */ /* parser->in_memory is set if we have a memory stream. */ /* */ if ( FT_STREAM_SEEK( 0L ) || FT_FRAME_ENTER( 17 ) ) goto Exit; if ( ft_memcmp( stream->cursor, "%!PS-TrueTypeFont", 17 ) != 0 ) { FT_TRACE2(( " not a Type42 font\n" )); error = FT_THROW( Unknown_File_Format ); } FT_FRAME_EXIT(); if ( error || FT_STREAM_SEEK( 0 ) ) goto Exit; size = stream->size; /* now, try to load `size' bytes of the `base' dictionary we */ /* found previously */ /* if it is a memory-based resource, set up pointers */ if ( !stream->read ) { parser->base_dict = (FT_Byte*)stream->base + stream->pos; parser->base_len = size; parser->in_memory = 1; /* check that the `size' field is valid */ if ( FT_STREAM_SKIP( size ) ) goto Exit; } else { /* read segment in memory */ if ( FT_ALLOC( parser->base_dict, size ) || FT_STREAM_READ( parser->base_dict, size ) ) goto Exit; parser->base_len = size; } parser->root.base = parser->base_dict; parser->root.cursor = parser->base_dict; parser->root.limit = parser->root.cursor + parser->base_len; Exit: if ( error && !parser->in_memory ) FT_FREE( parser->base_dict ); return error; }
t42_parse_dict( T42_Face face, T42_Loader loader, FT_Byte* base, FT_Long size ) { T42_Parser parser = &loader->parser; FT_Byte* limit; FT_Int n_keywords = (FT_Int)( sizeof ( t42_keywords ) / sizeof ( t42_keywords[0] ) ); parser->root.cursor = base; parser->root.limit = base + size; parser->root.error = FT_Err_Ok; limit = parser->root.limit; T1_Skip_Spaces( parser ); while ( parser->root.cursor < limit ) { FT_Byte* cur; cur = parser->root.cursor; /* look for `FontDirectory' which causes problems for some fonts */ if ( *cur == 'F' && cur + 25 < limit && ft_strncmp( (char*)cur, "FontDirectory", 13 ) == 0 ) { FT_Byte* cur2; /* skip the `FontDirectory' keyword */ T1_Skip_PS_Token( parser ); T1_Skip_Spaces ( parser ); cur = cur2 = parser->root.cursor; /* look up the `known' keyword */ while ( cur < limit ) { if ( *cur == 'k' && cur + 5 < limit && ft_strncmp( (char*)cur, "known", 5 ) == 0 ) break; T1_Skip_PS_Token( parser ); if ( parser->root.error ) goto Exit; T1_Skip_Spaces ( parser ); cur = parser->root.cursor; } if ( cur < limit ) { T1_TokenRec token; /* skip the `known' keyword and the token following it */ T1_Skip_PS_Token( parser ); T1_ToToken( parser, &token ); /* if the last token was an array, skip it! */ if ( token.type == T1_TOKEN_TYPE_ARRAY ) cur2 = parser->root.cursor; } parser->root.cursor = cur2; } /* look for immediates */ else if ( *cur == '/' && cur + 2 < limit ) { FT_PtrDist len; cur++; parser->root.cursor = cur; T1_Skip_PS_Token( parser ); if ( parser->root.error ) goto Exit; len = parser->root.cursor - cur; if ( len > 0 && len < 22 && parser->root.cursor < limit ) { int i; /* now compare the immediate name to the keyword table */ /* loop through all known keywords */ for ( i = 0; i < n_keywords; i++ ) { T1_Field keyword = (T1_Field)&t42_keywords[i]; FT_Byte *name = (FT_Byte*)keyword->ident; if ( !name ) continue; if ( cur[0] == name[0] && len == (FT_PtrDist)ft_strlen( (const char *)name ) && ft_memcmp( cur, name, len ) == 0 ) { /* we found it -- run the parsing callback! */ parser->root.error = t42_load_keyword( face, loader, keyword ); if ( parser->root.error ) return parser->root.error; break; } } } } else { T1_Skip_PS_Token( parser ); if ( parser->root.error ) goto Exit; } T1_Skip_Spaces( parser ); } Exit: return parser->root.error; }
/* Create a new FT_Face from an SFNT resource, specified by res ID. */ static FT_Error FT_New_Face_From_SFNT( FT_Library library, ResID sfnt_id, FT_Long face_index, FT_Face* aface ) { Handle sfnt = NULL; FT_Byte* sfnt_data; size_t sfnt_size; FT_Error error = FT_Err_Ok; FT_Memory memory = library->memory; int is_cff, is_sfnt_ps; sfnt = GetResource( TTAG_sfnt, sfnt_id ); if ( sfnt == NULL ) return FT_Err_Invalid_Handle; sfnt_size = (FT_ULong)GetHandleSize( sfnt ); if ( FT_ALLOC( sfnt_data, (FT_Long)sfnt_size ) ) { ReleaseResource( sfnt ); return error; } ft_memcpy( sfnt_data, *sfnt, sfnt_size ); ReleaseResource( sfnt ); is_cff = sfnt_size > 4 && !ft_memcmp( sfnt_data, "OTTO", 4 ); is_sfnt_ps = sfnt_size > 4 && !ft_memcmp( sfnt_data, "typ1", 4 ); if ( is_sfnt_ps ) { FT_Stream stream; if ( FT_NEW( stream ) ) goto Try_OpenType; FT_Stream_OpenMemory( stream, sfnt_data, sfnt_size ); if ( !open_face_PS_from_sfnt_stream( library, stream, face_index, 0, NULL, aface ) ) { FT_Stream_Close( stream ); FT_FREE( stream ); FT_FREE( sfnt_data ); goto Exit; } FT_FREE( stream ); } Try_OpenType: error = open_face_from_buffer( library, sfnt_data, sfnt_size, face_index, is_cff ? "cff" : "truetype", aface ); Exit: return error; }
void test_ft_memcmp(void) { int memcmp_1_tab1[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; int memcmp_1_tab2[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; int memcmp_2_tab2[10] = {0, 1, 2, 3, 4, 5, -20, 71, 11, -42}; assert_true(ft_memcmp("This is the same", "This is the same", 17) == 0); assert_true(ft_memcmp("This is the same", "This is different", 8) == 0); assert_true(ft_memcmp("This is the same", "This is different", 9) > 0); assert_true(ft_memcmp("", "", 10) == 0); assert_true(ft_memcmp("This is short", "This is shorter", 13) == 0); assert_true(ft_memcmp("This is short", "This is shorter", 14) < 0); assert_true(ft_memcmp("This is shorter", "This is short", 13) == 0); assert_true(ft_memcmp("This is shorter", "This is short", 14) > 0); assert_true(ft_memcmp("THIS IS BEFORE", "this is before", 14) < 0); assert_true(ft_memcmp("THIS IS BEFORE", "this is before", 1) < 0); assert_true(ft_memcmp(memcmp_1_tab1, memcmp_1_tab2, 40) == 0); assert_true(ft_memcmp(memcmp_1_tab1, memcmp_2_tab2, 20) == 0); assert_true(ft_memcmp(memcmp_1_tab1, memcmp_2_tab2, 24) == 0); assert_true(ft_memcmp(memcmp_1_tab1, memcmp_2_tab2, 28) < 0); }
static void unittest2(t_test *test) { mt_assert(ft_memcmp("ab\0ab", "ab\0ac", 6) != 0); }
static void unittest6(t_test *test) { mt_assert(ft_memcmp("\200", "\0", 1) > 0); }
static void unittest5(t_test *test) { mt_assert(ft_memcmp("aww", "bpp", 0) == 0); }
static void unittest4(t_test *test) { mt_assert(ft_memcmp("aab", "aac", 2) == 0); }
static void unittest3(t_test *test) { mt_assert(ft_memcmp("aaa", "aab", 4) < 0); }
/* caller's transform is adjusted for subpixel positioning */ static void cf2_font_setup( CF2_Font font, const CF2_Matrix* transform ) { /* pointer to parsed font object */ CFF_Decoder* decoder = font->decoder; FT_Bool needExtraSetup = FALSE; /* character space units */ CF2_Fixed boldenX = font->syntheticEmboldeningAmountX; CF2_Fixed boldenY = font->syntheticEmboldeningAmountY; CF2_Fixed ppem; /* clear previous error */ font->error = FT_Err_Ok; /* if a CID fontDict has changed, we need to recompute some cached */ /* data */ needExtraSetup = font->lastSubfont != cf2_getSubfont( decoder ); /* if ppem has changed, we need to recompute some cached data */ /* note: because of CID font matrix concatenation, ppem and transform */ /* do not necessarily track. */ ppem = cf2_getPpemY( decoder ); if ( font->ppem != ppem ) { font->ppem = ppem; needExtraSetup = TRUE; } /* copy hinted flag on each call */ font->hinted = font->renderingFlags & CF2_FlagsHinted; /* determine if transform has changed; */ /* include Fontmatrix but ignore translation */ if ( ft_memcmp( transform, &font->currentTransform, 4 * sizeof ( CF2_Fixed ) ) != 0 ) { /* save `key' information for `cache of one' matrix data; */ /* save client transform, without the translation */ font->currentTransform = *transform; font->currentTransform.tx = font->currentTransform.ty = cf2_intToFixed( 0 ); /* TODO: FreeType transform is simple scalar; for now, use identity */ /* for outer */ font->innerTransform = *transform; font->outerTransform.a = font->outerTransform.d = cf2_intToFixed( 1 ); font->outerTransform.b = font->outerTransform.c = cf2_intToFixed( 0 ); needExtraSetup = TRUE; } /* * font->darkened is set to true if there is a stem darkening request or * the font is synthetic emboldened. * font->darkened controls whether to adjust blue zones, winding order, * and hinting. * */ if ( font->stemDarkened != ( font->renderingFlags & CF2_FlagsDarkened ) ) { font->stemDarkened = font->renderingFlags & CF2_FlagsDarkened; /* blue zones depend on darkened flag */ needExtraSetup = TRUE; } /* recompute variables that are dependent on transform or FontDict or */ /* darken flag */ if ( needExtraSetup ) { /* StdVW is found in the private dictionary; */ /* recompute darkening amounts whenever private dictionary or */ /* transform change */ /* Note: a rendering flag turns darkening on or off, so we want to */ /* store the `on' amounts; */ /* darkening amount is computed in character space */ /* TODO: testing size-dependent darkening here; */ /* what to do for rotations? */ CF2_Fixed emRatio; CF2_Fixed stdHW; CF2_Int unitsPerEm = font->unitsPerEm; if ( unitsPerEm == 0 ) unitsPerEm = 1000; ppem = FT_MAX( cf2_intToFixed( 4 ), font->ppem ); /* use minimum ppem of 4 */ #if 0 /* since vstem is measured in the x-direction, we use the `a' member */ /* of the fontMatrix */ emRatio = cf2_fixedFracMul( cf2_intToFixed( 1000 ), fontMatrix->a ); #endif /* Freetype does not preserve the fontMatrix when parsing; use */ /* unitsPerEm instead. */ /* TODO: check precision of this */ emRatio = cf2_intToFixed( 1000 ) / unitsPerEm; font->stdVW = cf2_getStdVW( decoder ); if ( font->stdVW <= 0 ) font->stdVW = FT_DivFix( cf2_intToFixed( 75 ), emRatio ); if ( boldenX > 0 ) { /* Ensure that boldenX is at least 1 pixel for synthetic bold font */ /* (similar to what Avalon does) */ boldenX = FT_MAX( boldenX, FT_DivFix( cf2_intToFixed( unitsPerEm ), ppem ) ); /* Synthetic emboldening adds at least 1 pixel to darkenX, while */ /* stem darkening adds at most half pixel. Since the purpose of */ /* stem darkening (readability at small sizes) is met with */ /* synthetic emboldening, no need to add stem darkening for a */ /* synthetic bold font. */ cf2_computeDarkening( emRatio, ppem, font->stdVW, &font->darkenX, boldenX, FALSE ); } else cf2_computeDarkening( emRatio, ppem, font->stdVW, &font->darkenX, 0, font->stemDarkened ); #if 0 /* since hstem is measured in the y-direction, we use the `d' member */ /* of the fontMatrix */ /* TODO: use the same units per em as above; check this */ emRatio = cf2_fixedFracMul( cf2_intToFixed( 1000 ), fontMatrix->d ); #endif /* set the default stem width, because it must be the same for all */ /* family members; */ /* choose a constant for StdHW that depends on font contrast */ stdHW = cf2_getStdHW( decoder ); if ( stdHW > 0 && font->stdVW > 2 * stdHW ) font->stdHW = FT_DivFix( cf2_intToFixed( 75 ), emRatio ); else { /* low contrast font gets less hstem darkening */ font->stdHW = FT_DivFix( cf2_intToFixed( 110 ), emRatio ); } cf2_computeDarkening( emRatio, ppem, font->stdHW, &font->darkenY, boldenY, font->stemDarkened ); if ( font->darkenX != 0 || font->darkenY != 0 ) font->darkened = TRUE; else font->darkened = FALSE; font->reverseWinding = FALSE; /* initial expectation is CCW */ /* compute blue zones for this instance */ cf2_blues_init( &font->blues, font ); } }
int main(int argc, char **argv) { printf("%d", ft_memcmp(argv[1], argv[2], 4)); printf("\n%d", memcmp(argv[1], argv[2], 4)); }
int ft_strcmp(const char *s1, const char *s2) { return (ft_memcmp(s1, s2, ft_strlen(s1) + 1)); }
int ft_strcmp(const char *s1, const char *s2) { return (ft_memcmp((void *)s1, (void *)s2, ft_strlen(s1) + 1)); }
int event_match(t_event elem1, t_event elem2, t_event *mask) { apply_mask((char *)&event1, (char *)mask, sizeof(t_event)); apply_mask((char *)&event2, (char *)mask, sizeof(t_event)); return ((ft_memcmp((char *)&elem1, (char *)&elem2, sizeof(t_event)) != 0)); }