|
Packit Service |
4684c1 |
/* Test of ftello() function.
|
|
Packit Service |
4684c1 |
Copyright (C) 2007-2020 Free Software Foundation, Inc.
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
This program is free software: you can redistribute it and/or modify
|
|
Packit Service |
4684c1 |
it under the terms of the GNU General Public License as published by
|
|
Packit Service |
4684c1 |
the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
4684c1 |
(at your option) any later version.
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
This program is distributed in the hope that it will be useful,
|
|
Packit Service |
4684c1 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
4684c1 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
4684c1 |
GNU General Public License for more details.
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
You should have received a copy of the GNU General Public License
|
|
Packit Service |
4684c1 |
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include <config.h>
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* None of the files accessed by this test are large, so disable the
|
|
Packit Service |
4684c1 |
fseek link warning if we are not using the gnulib fseek module. */
|
|
Packit Service |
4684c1 |
#define _GL_NO_LARGE_FILES
|
|
Packit Service |
4684c1 |
#include <stdio.h>
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include "signature.h"
|
|
Packit Service |
4684c1 |
SIGNATURE_CHECK (ftello, off_t, (FILE *));
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include "binary-io.h"
|
|
Packit Service |
4684c1 |
#include "macros.h"
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#ifndef FUNC_UNGETC_BROKEN
|
|
Packit Service |
4684c1 |
# define FUNC_UNGETC_BROKEN 0
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
int
|
|
Packit Service |
4684c1 |
main (int argc, char **argv _GL_UNUSED)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
int ch;
|
|
Packit Service |
4684c1 |
/* Assume stdin is seekable iff argc > 1. */
|
|
Packit Service |
4684c1 |
if (argc == 1)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
ASSERT (ftell (stdin) == -1);
|
|
Packit Service |
4684c1 |
ASSERT (ftello (stdin) == -1);
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* mingw ftell is unreliable on text mode input. */
|
|
Packit Service |
4684c1 |
set_binary_mode (0, O_BINARY);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Simple tests. For each test, make sure ftell and ftello agree. */
|
|
Packit Service |
4684c1 |
ASSERT (ftell (stdin) == 0);
|
|
Packit Service |
4684c1 |
ASSERT (ftello (stdin) == 0);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ch = fgetc (stdin);
|
|
Packit Service |
4684c1 |
ASSERT (ch == '#');
|
|
Packit Service |
4684c1 |
ASSERT (ftell (stdin) == 1);
|
|
Packit Service |
4684c1 |
ASSERT (ftello (stdin) == 1);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Test ftell after ungetc of read input. */
|
|
Packit Service |
4684c1 |
ch = ungetc ('#', stdin);
|
|
Packit Service |
4684c1 |
ASSERT (ch == '#');
|
|
Packit Service |
4684c1 |
ASSERT (ftell (stdin) == 0);
|
|
Packit Service |
4684c1 |
ASSERT (ftello (stdin) == 0);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ch = fgetc (stdin);
|
|
Packit Service |
4684c1 |
ASSERT (ch == '#');
|
|
Packit Service |
4684c1 |
ASSERT (ftell (stdin) == 1);
|
|
Packit Service |
4684c1 |
ASSERT (ftello (stdin) == 1);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Test ftell after fseek. */
|
|
Packit Service |
4684c1 |
ASSERT (fseek (stdin, 2, SEEK_SET) == 0);
|
|
Packit Service |
4684c1 |
ASSERT (ftell (stdin) == 2);
|
|
Packit Service |
4684c1 |
ASSERT (ftello (stdin) == 2);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Test ftell after random ungetc. */
|
|
Packit Service |
4684c1 |
ch = fgetc (stdin);
|
|
Packit Service |
4684c1 |
ASSERT (ch == '/');
|
|
Packit Service |
4684c1 |
ch = ungetc ('@', stdin);
|
|
Packit Service |
4684c1 |
ASSERT (ch == '@');
|
|
Packit Service |
4684c1 |
ASSERT (ftell (stdin) == 2);
|
|
Packit Service |
4684c1 |
ASSERT (ftello (stdin) == 2);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ch = fgetc (stdin);
|
|
Packit Service |
4684c1 |
ASSERT (ch == '@');
|
|
Packit Service |
4684c1 |
ASSERT (ftell (stdin) == 3);
|
|
Packit Service |
4684c1 |
ASSERT (ftello (stdin) == 3);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (2 < argc)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
if (FUNC_UNGETC_BROKEN)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
fputs ("Skipping test: ungetc cannot handle arbitrary bytes\n",
|
|
Packit Service |
4684c1 |
stderr);
|
|
Packit Service |
4684c1 |
return 77;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
/* Test ftell after ungetc without read. */
|
|
Packit Service |
4684c1 |
ASSERT (fseek (stdin, 0, SEEK_CUR) == 0);
|
|
Packit Service |
4684c1 |
ASSERT (ftell (stdin) == 3);
|
|
Packit Service |
4684c1 |
ASSERT (ftello (stdin) == 3);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ch = ungetc ('~', stdin);
|
|
Packit Service |
4684c1 |
ASSERT (ch == '~');
|
|
Packit Service |
4684c1 |
ASSERT (ftell (stdin) == 2);
|
|
Packit Service |
4684c1 |
ASSERT (ftello (stdin) == 2);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#if !defined __MINT__ /* FreeMiNT has problems seeking past end of file */
|
|
Packit Service |
4684c1 |
/* Test ftell beyond end of file. */
|
|
Packit Service |
4684c1 |
ASSERT (fseek (stdin, 0, SEEK_END) == 0);
|
|
Packit Service |
4684c1 |
ch = ftello (stdin);
|
|
Packit Service |
4684c1 |
ASSERT (fseek (stdin, 10, SEEK_END) == 0);
|
|
Packit Service |
4684c1 |
ASSERT (ftell (stdin) == ch + 10);
|
|
Packit Service |
4684c1 |
ASSERT (ftello (stdin) == ch + 10);
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|