Edit

kc3-lang/gnulib/tests/test-fseeko.c

Branch :

  • Show log

    Commit

  • Author : Eric Blake
    Date : 2009-12-22 15:14:49
    Hash : 169ab5de
    Message : gnulib-common: prefer _GL_UNUSED over _UNUSED_PARAMETER_ There are more contexts where __attribute__((__unused__)) is useful than just parameter lists. Also, naming the macro _GL_UNUSED fits with the recent addition of _GL_ARG_NONNULL. Preserve the name _UNUSED_PARAMETER_ for backwards-compatible use in external projects. * m4/gnulib-common.m4 (gl_COMMON): Create a more-appropriately named alias for __attribute__((__unused__)). * lib/chown.c: Update client. * lib/fchmodat.c: Likewise. * lib/fts.c: Likewise. * lib/getdate.y: Likewise. * lib/getgroups.c: Likewise. * lib/getopt.c: Likewise. * lib/getugroups.c: Likewise. * lib/mkdir.c: Likewise. * lib/mkfifo.c: Likewise. * lib/mkfifoat.c: Likewise. * lib/mknod.c: Likewise. * lib/mknodat.c: Likewise. * lib/readlink.c: Likewise. * lib/se-context.in.h: Likewise. * lib/se-selinux.in.h: Likewise. * lib/sockets.c: Likewise. * lib/symlink.c: Likewise. * lib/symlinkat.c: Likewise. * lib/unicodeio.c: Likewise. * lib/unistr.h: Likewise. * tests/test-areadlink.c: Likewise. * tests/test-areadlinkat.c: Likewise. * tests/test-filenamecat.c: Likewise. * tests/test-fseeko.c: Likewise. * tests/test-ftello.c: Likewise. * tests/test-getdate.c: Likewise. * tests/test-getgroups.c: Likewise. * tests/test-gethostname.c: Likewise. * tests/test-quotearg.c: Likewise. * tests/test-version-etc.c: Likewise. * tests/test-xalloc-die.c: Likewise. * tests/test-xfprintf-posix.c: Likewise. * tests/test-xprintf-posix.c: Likewise. * tests/test-xvasprintf.c: Likewise. Signed-off-by: Eric Blake <ebb9@byu.net>

  • tests/test-fseeko.c
  • /* Test of fseeko() function.
       Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
    
       This program is free software: you can redistribute it and/or modify
       it under the terms of the GNU General Public License as published by
       the Free Software Foundation; either version 3 of the License, or
       (at your option) any later version.
    
       This program is distributed in the hope that it will be useful,
       but WITHOUT ANY WARRANTY; without even the implied warranty of
       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       GNU General Public License for more details.
    
       You should have received a copy of the GNU General Public License
       along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
    
    /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
    
    #include <config.h>
    
    /* None of the files accessed by this test are large, so disable the
       fseek link warning if we are not using the gnulib fseek module.  */
    #if !GNULIB_FSEEK
    # undef GL_LINK_WARNING
    # define GL_LINK_WARNING(ignored) ((void) 0)
    #endif
    
    #include <stdio.h>
    #include <stdlib.h>
    
    #define ASSERT(expr) \
      do                                                                         \
        {                                                                        \
          if (!(expr))                                                           \
            {                                                                    \
              fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
              fflush (stderr);                                                   \
              abort ();                                                          \
            }                                                                    \
        }                                                                        \
      while (0)
    
    #ifndef FUNC_UNGETC_BROKEN
    # define FUNC_UNGETC_BROKEN 0
    #endif
    
    int
    main (int argc, char **argv _GL_UNUSED)
    {
      /* Assume stdin is non-empty, seekable, and starts with '#!/bin/sh'
         iff argc > 1.  */
      int expected = argc > 1 ? 0 : -1;
      /* Exit with success only if fseek/fseeko agree.  */
      int r1 = fseeko (stdin, 0, SEEK_CUR);
      int r2 = fseek (stdin, 0, SEEK_CUR);
      ASSERT (r1 == r2 && r1 == expected);
      if (argc > 1)
        {
          /* Test that fseek discards previously read ungetc data.  */
          int ch = fgetc (stdin);
          ASSERT (ch == '#');
          ASSERT (ungetc (ch, stdin) == ch);
          ASSERT (fseeko (stdin, 2, SEEK_SET) == 0);
          ch = fgetc (stdin);
          ASSERT (ch == '/');
          if (2 < argc)
            {
              if (FUNC_UNGETC_BROKEN)
                {
                  fputs ("Skipping test: ungetc cannot handle arbitrary bytes\n",
                         stderr);
                  return 77;
                }
              /* Test that fseek discards random ungetc data.  */
              ASSERT (ungetc (ch ^ 0xff, stdin) == (ch ^ 0xff));
            }
          ASSERT (fseeko (stdin, 0, SEEK_END) == 0);
          ASSERT (fgetc (stdin) == EOF);
          /* Test that fseek resets end-of-file marker.  */
          ASSERT (feof (stdin));
          ASSERT (fseeko (stdin, 0, SEEK_END) == 0);
          ASSERT (!feof (stdin));
        }
      return 0;
    }