[PATCH] stdio-common: Avoid spurious mtime/ctime-related failure in tst-fseek

Florian Weimer fweimer@redhat.com
Wed Sep 2 14:13:31 GMT 2026


* Andreas Schwab:

> On Sep 02 2026, Florian Weimer wrote:
>
>> diff --git a/stdio-common/tst-fseek.c b/stdio-common/tst-fseek.c
>> index 086ede5967..64f1e0a057 100644
>> --- a/stdio-common/tst-fseek.c
>> +++ b/stdio-common/tst-fseek.c
>> @@ -345,12 +345,14 @@ do_test (void)
>>  	      printf ("%d: st_mtime not updated\n", __LINE__);
>>  	      result = 1;
>>  	    }
>> -	  if (st1.st_ctime >= st2.st_ctime)
>> +	  if (st1.st_ctime >= st2.st_ctime
>> +	      && st1.st_ctim.tv_nsec == st2.st_ctim.tv_nsec)
>>  	    {
>>  	      printf ("%d: st_ctime not changed\n", __LINE__);
>>  	      result = 1;
>>  	    }
>> -	  if (st1.st_mtime >= st2.st_mtime)
>> +	  if (st1.st_mtime >= st2.st_mtime
>> +	      && st1.st_mtim.tv_nsec == st2.st_mtim.tv_nsec)
>>  	    {
>>  	      printf ("%d: st_mtime not changed\n", __LINE__);
>>  	      result = 1;
>
> What about the other two conditions before those?  It's also strange to
> use >= instead of ==, as if the test tries to handle time going
> backwards in some way.

We haven't seen those failing.  Should we delete them?  Then we would
end up with this?

diff --git a/stdio-common/tst-fseek.c b/stdio-common/tst-fseek.c
index 086ede5967..4fc38b09e0 100644
--- a/stdio-common/tst-fseek.c
+++ b/stdio-common/tst-fseek.c
@@ -325,32 +325,22 @@ do_test (void)
       else
        {
 
-         time_t t;
          /* Make sure the timestamp actually can be different.  */
          sleep (1);
-         t = time (NULL);
 
          if (fstat64 (fd, &st2) < 0)
            {
              printf ("%d: fstat64() after fseeko() failed\n\n", __LINE__);
              result = 1;
            }
-         if (st1.st_ctime >= t)
-           {
-             printf ("%d: st_ctime not updated\n", __LINE__);
-             result = 1;
-           }
-         if (st1.st_mtime >= t)
-           {
-             printf ("%d: st_mtime not updated\n", __LINE__);
-             result = 1;
-           }
-         if (st1.st_ctime >= st2.st_ctime)
+         if (st1.st_ctime == st2.st_ctime
+             && st1.st_ctim.tv_nsec == st2.st_ctim.tv_nsec)
            {
              printf ("%d: st_ctime not changed\n", __LINE__);
              result = 1;
            }
-         if (st1.st_mtime >= st2.st_mtime)
+         if (st1.st_mtime == st2.st_mtime
+             && st1.st_mtim.tv_nsec == st2.st_mtim.tv_nsec)
            {
              printf ("%d: st_mtime not changed\n", __LINE__);
              result = 1;

Thanks,
Florian



More information about the Libc-alpha mailing list