Blame src/gl/ftell.c

Packit aea12f
/* An ftell() function that works around platform bugs.
Packit Service 991b93
   Copyright (C) 2007-2020 Free Software Foundation, Inc.
Packit aea12f
Packit aea12f
   This program is free software: you can redistribute it and/or modify
Packit aea12f
   it under the terms of the GNU General Public License as published by
Packit aea12f
   the Free Software Foundation; either version 3 of the License, or
Packit aea12f
   (at your option) any later version.
Packit aea12f
Packit aea12f
   This program is distributed in the hope that it will be useful,
Packit aea12f
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit aea12f
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit aea12f
   GNU General Public License for more details.
Packit aea12f
Packit aea12f
   You should have received a copy of the GNU General Public License
Packit aea12f
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
Packit aea12f
Packit aea12f
#include <config.h>
Packit aea12f
Packit aea12f
/* Specification.  */
Packit aea12f
#include <stdio.h>
Packit aea12f
Packit aea12f
#include <errno.h>
Packit aea12f
#include <limits.h>
Packit aea12f
Packit aea12f
long
Packit aea12f
ftell (FILE *fp)
Packit aea12f
{
Packit aea12f
  /* Use the replacement ftello function with all its workarounds.  */
Packit aea12f
  off_t offset = ftello (fp);
Packit aea12f
  if (LONG_MIN <= offset && offset <= LONG_MAX)
Packit aea12f
    return /* (long) */ offset;
Packit aea12f
  else
Packit aea12f
    {
Packit aea12f
      errno = EOVERFLOW;
Packit aea12f
      return -1;
Packit aea12f
    }
Packit aea12f
}