CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/ext/libpng17/pngrio.c
Views: 1401
1/* pngrio.c - functions for data input2*3* Last changed in libpng 1.7.0 [(PENDING RELEASE)]4* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson5* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)6* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)7*8* This code is released under the libpng license.9* For conditions of distribution and use, see the disclaimer10* and license in png.h11*12* This file provides a location for all input. Users who need13* special handling are expected to write a function that has the same14* arguments as this and performs a similar function, but that possibly15* has a different input method. Note that you shouldn't change this16* function, but rather write a replacement function and then make17* libpng use it at run time with png_set_read_fn(...).18*/1920#include "pngpriv.h"21#define PNG_SRC_FILE PNG_SRC_FILE_pngrio2223#ifdef PNG_READ_SUPPORTED2425/* Read the data from whatever input you are using. The default routine26* reads from a file pointer. Note that this routine sometimes gets called27* with very small lengths, so you should implement some kind of simple28* buffering if you are using unbuffered reads. This should never be asked29* to read more than 64K on a 16 bit machine.30*/31void /* PRIVATE */32png_read_data(png_structrp png_ptr, png_voidp data, png_size_t length)33{34png_debug1(4, "reading %d bytes", (int)length);3536/* This was guaranteed by prior versions of libpng, so app callbacks may37* assume it even though it isn't documented to be the case.38*/39debug(length > 0U);4041if (png_ptr->rw_data_fn != NULL)42png_ptr->rw_data_fn(png_ptr, png_voidcast(png_bytep,data), length);4344else45png_app_error(png_ptr, "No read function");46}4748#ifdef PNG_STDIO_SUPPORTED49/* This is the function that does the actual reading of data. If you are50* not reading from a standard C stream, you should create a replacement51* read_data function and use it at run time with png_set_read_fn(), rather52* than changing the library.53*/54void PNGCBAPI55png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)56{57png_size_t check;5859if (png_ptr == NULL)60return;6162/* fread() returns 0 on error, so it is OK to store this in a png_size_t63* instead of an int, which is what fread() actually returns.64*/65check = fread(data, 1, length, png_voidcast(png_FILE_p, png_ptr->io_ptr));6667if (check != length)68png_error(png_ptr, "Read Error");69}70#endif /* STDIO */7172/* This function allows the application to supply a new input function73* for libpng if standard C streams aren't being used.74*75* This function takes as its arguments:76*77* png_ptr - pointer to a png input data structure78*79* io_ptr - pointer to user supplied structure containing info about80* the input functions. May be NULL.81*82* read_data_fn - pointer to a new input function that takes as its83* arguments a pointer to a png_struct, a pointer to84* a location where input data can be stored, and a 32-bit85* unsigned int that is the number of bytes to be read.86* To exit and output any fatal error messages the new write87* function should call png_error(png_ptr, "Error msg").88* May be NULL, in which case libpng's default function will89* be used.90*/91void PNGAPI92png_set_read_fn(png_structrp png_ptr, png_voidp io_ptr,93png_rw_ptr read_data_fn)94{95if (png_ptr == NULL)96return;9798if (!png_ptr->read_struct)99{100png_app_error(png_ptr, "cannot set a read function on a write struct");101return;102}103104if (read_data_fn == NULL)105{106png_app_error(png_ptr, "API change: png_set_read_fn requires a function");107return;108}109110png_ptr->io_ptr = io_ptr;111png_ptr->rw_data_fn = read_data_fn;112}113#endif /* READ */114115116