FT_Stream_Open( FT_Stream stream, const char* filepathname ) { FT_FILE* file; if ( !stream ) return FT_Err_Invalid_Stream_Handle; file = ft_fopen( filepathname, "rb" ); if ( !file ) { FT_ERROR(( "FT_Stream_Open:" " could not open `%s'\n", filepathname )); return FT_Err_Cannot_Open_Resource; } ft_fseek( file, 0, SEEK_END ); stream->size = ft_ftell( file ); ft_fseek( file, 0, SEEK_SET ); stream->descriptor.pointer = file; stream->pathname.pointer = (char*)filepathname; stream->pos = 0; stream->read = ft_ansi_stream_io; stream->close = ft_ansi_stream_close; FT_TRACE1(( "FT_Stream_Open:" )); FT_TRACE1(( " opened `%s' (%d bytes) successfully\n", filepathname, stream->size )); return FT_Err_Ok; }
char *ft_file_get_contents(char *filename, int offset, int len) { char *buffer; char *ctn; char *tmpCtn; int fd; size_t resRead; if ((fd = ft_fopen(filename, "r")) <= 0) return (NULL); buffer = ft_strnew(1024); ctn = ft_strnew(1024); while ((resRead = read(fd, buffer, 1024)) > 0) { if (resRead < 1024) buffer[resRead] = '\0'; tmpCtn = ft_strnew(ft_strlen(ctn) + resRead); tmpCtn = ft_strcpy(tmpCtn, ctn); tmpCtn = ft_strcat(tmpCtn, buffer); ctn = tmpCtn; } if (offset != 0 && (int)(ft_strlen(ctn)) > offset) ctn = ft_strcut(ctn, offset); if (len != 0) ctn = ft_strcutend(ctn, len); return (ctn); }