jnp@mjolner.tele.nokia.fi (J|rgen N|rgaard) (02/02/90)
On installing perl (latest release with patches) I had some worries
because the tests some times would fail on "op.stat". Deciding to
investigate on little on this I wrote the attached small c-piece.
So my question os two-fold:
i) how is "stat" supposed to work under BSD4.3 ?
i.e. should "mtime" and "ctime" be equal upon
creating of a fresh file ?
ii) If so, why is Apollo different ? And what to do about it ?
Is this fixed in SR10.2 ?
(Machine: Apollo DN3500, SR10.1, BSD4.3, native cc)
Any help appreciated.
/j|rgen n|rgaard
File "stat.c":
#include <stdio.h>
#include <sys/errno.h>
#include <sys/file.h>
#include <sys/types.h>
#include <sys/stat.h>
main(argc,argv)
int argc;
char *argv[];
{
int fd;
struct stat buf;
(void) unlink("./foo.tmp");
fd = open("./foo.tmp", O_CREAT | O_RDWR, 00200);
printf("fd: %d, %d.\n", fd, errno);
printf("stat: %d.\n", stat("./foo.tmp", &buf));
printf("stat.st_mtime: %u, stat.st_ctime: %u.\n", buf.st_mtime, buf.st_ctime);
printf("stat: %d.\n", stat("./foo.tmp", &buf));
printf("stat.st_mtime: %u, stat.st_ctime: %u.\n", buf.st_mtime, buf.st_ctime);
(void) unlink("foo.tmp");
};
Result:
mjolner :~/src/c/test (1) a.out
fd: 3, 2.
stat: 0.
stat.st_mtime: 633958917, stat.st_ctime: 633958918.
stat: 0.
stat.st_mtime: 633958917, stat.st_ctime: 633958918.
mjolner :~/src/c/test (2) !!
a.out
fd: 3, 2.
stat: 0.
stat.st_mtime: 633958924, stat.st_ctime: 633958924.
stat: 0.
stat.st_mtime: 633958924, stat.st_ctime: 633958924.
mjolner :~/src/c/test (3) !!
a.out
fd: 3, 2.
stat: 0.
stat.st_mtime: 633958926, stat.st_ctime: 633958927.
stat: 0.
stat.st_mtime: 633958926, stat.st_ctime: 633958927.
mjolner :~/src/c/test (4) !!
a.out
fd: 3, 2.
stat: 0.
stat.st_mtime: 633958929, stat.st_ctime: 633958929.
stat: 0.
stat.st_mtime: 633958929, stat.st_ctime: 633958929.
mjolner :~/src/c/test (5)
--
------------------------ ORIGIN '~jnp/stdDisclaimers' ------------------------
| Regards, J|rgen N|rgaard ('|' is '\o{}' in \LaTeX{}) |
| e-mail: jnp@tele.nokia.fi | telephone: <..>-358-0-511-5671 |
-- mail: Nokia Telecommunications, PL 33, SF-02601 Espoo, Suomi Finland --carlton@apollo.HP.COM (Carlton B. Hommel) (02/04/90)
A summary of the problem: The "ctime" and "mtime" reported
by stat(2) are different for a newly created file, when you
would expect them to be the same. Ie,
stat.st_mtime: 634104703 stat.st_ctime: 634104704
I'm pretty sure that it is a byproduct of our implementation
of the open(2) system call, but I'm just a perl fanatic, and
not a systems hacker.
This problem still exists at our hot-off-the-presses sr10.2+
baselevel, so I've posted it as a bug. If you want a formal
answer, then please submit an APR. (See "man mkapr" for help.)
Carl Hommel
carlton@apollo.hp.com
"I could write a perl script to do that for you..."