Imported Upstream version 1.5
[debian/gzip] / lib / closein.c
index 077a3247d60ffa39e896dab2d718015919371d07..65f2cb9e98bc06faa49d69572d6952aa2b496fa1 100644 (file)
@@ -1,6 +1,6 @@
 /* Close standard input, rewinding seekable stdin if necessary.
 
 /* Close standard input, rewinding seekable stdin if necessary.
 
-   Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2009-2012 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
 
    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
@@ -55,7 +55,7 @@ close_stdin_set_file_name (const char *file)
    For example, POSIX requires that these two commands behave alike:
 
      (sed -ne 1q; cat) < file
    For example, POSIX requires that these two commands behave alike:
 
      (sed -ne 1q; cat) < file
-     tail -n 1 file
+     tail -n +2 file
 
    Since close_stdin is commonly registered via 'atexit', POSIX
    and the C standard both say that it should not call 'exit',
 
    Since close_stdin is commonly registered via 'atexit', POSIX
    and the C standard both say that it should not call 'exit',
@@ -72,7 +72,7 @@ close_stdin_set_file_name (const char *file)
    the removal of these files.
 
    It's important to detect such failures and exit nonzero because many
    the removal of these files.
 
    It's important to detect such failures and exit nonzero because many
-   tools (most notably `make' and other build-management systems) depend
+   tools (most notably 'make' and other build-management systems) depend
    on being able to detect failure in other tools via their exit status.  */
 
 void
    on being able to detect failure in other tools via their exit status.  */
 
 void
@@ -82,7 +82,8 @@ close_stdin (void)
 
   /* There is no need to flush stdin if we can determine quickly that stdin's
      input buffer is empty; in this case we know that if stdin is seekable,
 
   /* There is no need to flush stdin if we can determine quickly that stdin's
      input buffer is empty; in this case we know that if stdin is seekable,
-     fseeko (stdin, 0, SEEK_CUR) == lseek (0, 0, SEEK_CUR).  */
+     (fseeko (stdin, 0, SEEK_CUR), ftello (stdin))
+     == lseek (0, 0, SEEK_CUR).  */
   if (freadahead (stdin) > 0)
     {
       /* Only attempt flush if stdin is seekable, as fflush is entitled to
   if (freadahead (stdin) > 0)
     {
       /* Only attempt flush if stdin is seekable, as fflush is entitled to