Path: blob/master/src/java.desktop/share/native/libsplashscreen/libpng/pngrio.c
41155 views
/*1* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation. Oracle designates this6* particular file as subject to the "Classpath" exception as provided7* by Oracle in the LICENSE file that accompanied this code.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/* pngrio.c - functions for data input25*26* This file is available under and governed by the GNU General Public27* License version 2 only, as published by the Free Software Foundation.28* However, the following notice accompanied the original version of this29* file and, per its terms, should not be removed:30*31* Copyright (c) 2018 Cosmin Truta32* Copyright (c) 1998-2002,2004,2006-2016,2018 Glenn Randers-Pehrson33* Copyright (c) 1996-1997 Andreas Dilger34* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.35*36* This code is released under the libpng license.37* For conditions of distribution and use, see the disclaimer38* and license in png.h39*40* This file provides a location for all input. Users who need41* special handling are expected to write a function that has the same42* arguments as this and performs a similar function, but that possibly43* has a different input method. Note that you shouldn't change this44* function, but rather write a replacement function and then make45* libpng use it at run time with png_set_read_fn(...).46*/4748#include "pngpriv.h"4950#ifdef PNG_READ_SUPPORTED5152/* Read the data from whatever input you are using. The default routine53* reads from a file pointer. Note that this routine sometimes gets called54* with very small lengths, so you should implement some kind of simple55* buffering if you are using unbuffered reads. This should never be asked56* to read more than 64K on a 16-bit machine.57*/58void /* PRIVATE */59png_read_data(png_structrp png_ptr, png_bytep data, size_t length)60{61png_debug1(4, "reading %d bytes", (int)length);6263if (png_ptr->read_data_fn != NULL)64(*(png_ptr->read_data_fn))(png_ptr, data, length);6566else67png_error(png_ptr, "Call to NULL read function");68}6970#ifdef PNG_STDIO_SUPPORTED71/* This is the function that does the actual reading of data. If you are72* not reading from a standard C stream, you should create a replacement73* read_data function and use it at run time with png_set_read_fn(), rather74* than changing the library.75*/76void PNGCBAPI77png_default_read_data(png_structp png_ptr, png_bytep data, size_t length)78{79size_t check;8081if (png_ptr == NULL)82return;8384/* fread() returns 0 on error, so it is OK to store this in a size_t85* instead of an int, which is what fread() actually returns.86*/87check = fread(data, 1, length, png_voidcast(png_FILE_p, png_ptr->io_ptr));8889if (check != length)90png_error(png_ptr, "Read Error");91}92#endif9394/* This function allows the application to supply a new input function95* for libpng if standard C streams aren't being used.96*97* This function takes as its arguments:98*99* png_ptr - pointer to a png input data structure100*101* io_ptr - pointer to user supplied structure containing info about102* the input functions. May be NULL.103*104* read_data_fn - pointer to a new input function that takes as its105* arguments a pointer to a png_struct, a pointer to106* a location where input data can be stored, and a 32-bit107* unsigned int that is the number of bytes to be read.108* To exit and output any fatal error messages the new write109* function should call png_error(png_ptr, "Error msg").110* May be NULL, in which case libpng's default function will111* be used.112*/113void PNGAPI114png_set_read_fn(png_structrp png_ptr, png_voidp io_ptr,115png_rw_ptr read_data_fn)116{117if (png_ptr == NULL)118return;119120png_ptr->io_ptr = io_ptr;121122#ifdef PNG_STDIO_SUPPORTED123if (read_data_fn != NULL)124png_ptr->read_data_fn = read_data_fn;125126else127png_ptr->read_data_fn = png_default_read_data;128#else129png_ptr->read_data_fn = read_data_fn;130#endif131132#ifdef PNG_WRITE_SUPPORTED133/* It is an error to write to a read device */134if (png_ptr->write_data_fn != NULL)135{136png_ptr->write_data_fn = NULL;137png_warning(png_ptr,138"Can't set both read_data_fn and write_data_fn in the"139" same structure");140}141#endif142143#ifdef PNG_WRITE_FLUSH_SUPPORTED144png_ptr->output_flush_fn = NULL;145#endif146}147#endif /* READ */148149150