Subject: modification time of standard input is wrong
From: Denis Excoffier <[email-masked]>
To: [email-masked]
Cc: Denis Excoffier <[email-masked]>
Date: Tue, 16 Mar 2010 18:24:27 +0100
List-Id: <cygwin.cygwin.com>

Hello,

Under Cygwin 1.7.1-1, i have created the small program (see below),
to print the modification time of the standard input. In the case where
the stdin is a pipe (or the terminal), i expect the result to be more
or less the current time. But the time printed in this case is
invariably the modification time of /dev/null.

This has some impact in gzip and further, in tar.

Thank you for your help. See below for the details.

Denis Excoffier.

---------------------------------
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>

//
int main() {
//
  struct stat s;
  if (fstat(fileno(stdin), &s) != 0) {
   fprintf(stderr, "error fstat\n");
  } else {
   struct tm *tm = localtime(&s.st_mtime);
   if (tm) {
    printf("%u\n", s.st_mtime);
    printf("%04u-%02u-%02u %02u:%02u:%02u\n", 1900 + tm->tm_year,
     1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
   } else {
     fprintf(stderr, "error localtime\n");
   };
  };
  return(0);
};
---------------------------------

% uname -s
CYGWIN_NT-5.1
% setenv TZ UTC
% gcc -o myprog myprog.c
% ./myprog < myprog.c
1268727969
2010-03-16 08:26:09
% ./myprog
1164931200
2006-12-01 00:00:00
% ls -lgG --full-time /dev/null
crw-rw-rw- 1 1, 3 2006-12-01 00:00:00.000000000 +0000 /dev/null
% tar czf - /etc/passwd | (od --skip-bytes=4 -l -N4; cat > /dev/null)
tar: Removing leading `/' from member names
0000004  1164931200
0000010
%

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple