From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (qmail 24133 invoked from network); 19 May 1999 10:12:15 -0000 Received: from mail.redhat.com (199.183.24.239) by lists.redhat.com with SMTP; 19 May 1999 10:12:15 -0000 Received: from axl01it.ntc.nokia.com (axl01it.ntc.nokia.com [131.228.118.232]) by mail.redhat.com (8.8.7/8.8.7) with ESMTP id FAA25212 for ; Wed, 19 May 1999 05:33:23 -0400 Received: from ducati.uk.ntc.nokia.com (ducati.uk.ntc.nokia.com [131.228.132.169]) by axl01it.ntc.nokia.com (8.8.5/8.6.9) with ESMTP id MAA24455 for ; Wed, 19 May 1999 12:32:15 +0300 (EET DST) Received: from mvagusta (mvagusta [131.228.132.173]) by ducati.uk.ntc.nokia.com (8.6.9/8.6.9) with ESMTP id KAA18601 for ; Wed, 19 May 1999 10:33:13 +0100 From: Phil Carmody Received: (carmody@localhost) by mvagusta (SMI-8.6/8.6.9) id KAA08264; Wed, 19 May 1999 10:33:12 +0100 Date: Wed, 19 May 1999 10:33:12 +0100 Message-Id: <199905190933.KAA08264@mvagusta> To: axp-list@redhat.com In-reply-to: <9905190951.ZM11753@dns.rgn.it> (franco@dns.rgn.it) Subject: Re: Converting time (since 01-01-1970) to Epoch Mime-Version: 1.0 (generated by tm-edit 7.68) Content-Type: text/plain; charset=US-ASCII >>>>> "Franco" == Franco Tassone writes: Franco> I have a binary file with record fixed lenght, it has been written on an SGI Franco> box (Irix 6.2) using the following structure: Franco> (/usr/include/rpcsvc/rusers.h) Franco> struct rusers_utmp { Franco> char ut_line[8]; /* tty name */ Franco> char ut_name[8]; /* user id */ Franco> char ut_host[16]; /* host name, if remote */ Franco> long ut_time; /* time on */ Franco> }; Franco> For the SGI box, sizeof(long) = 4. Franco> So I've converted the file, rewriting all the records on an Alpha-Linux box Franco> (kernel 2.2.7) using the following structure: Franco> (/usr/include/rpcsvc/rusers.h) Franco> struct ru_utmp { Franco> char ut_line[8]; /* tty name */ Franco> char ut_name[8]; /* user id */ Franco> char ut_host[16]; /* host name, if remote */ Franco> long ut_time; /* time on */ Franco> }; Franco> For Alpha-Linux box, sizeof(long) = 8. Franco> My conversion program does only a field's level assignments, and rewrites the Franco> new file, due to different sizeof(long). Franco> The resulting dates (ut_time in ru_utmp) are all garbled. Franco> Any ideas ? Any program which uses the above two structures will fail, because they are the same structure, there is no conversion. If you're running on the SGI, then you need to read structs rusers_utmp and write struct rusers_64out { char ut_line[8]; /* tty name */ char ut_name[8]; /* user id */ char ut_host[16]; /* host name, if remote */ long padding; /* set to zero (the other 32 bits) */ long ut_time; /* time on (32 bits) */ }; I may have the ut_time and padding in the wrong order - I'm assuming endianness. If your're running on the Alpha, then you need to read struct rusers_32in { char ut_line[8]; /* tty name */ char ut_name[8]; /* user id */ char ut_host[16]; /* host name, if remote */ int ut_time; /* time on (32 bits) */ }; and write structs ru_utmp. If your program doesn't work, pop up gdb, read in one record, check its value in the input structure, check it's value in the output structure (erm you could even use printf to help you do your debugging - blimey!) and check it's written out to file. When you have it working for _one_ record, then try the whole file. Learn to use the tools that come with the language and the system. Phil