Changeset 167

Show
Ignore:
Timestamp:
06/15/05 13:35:38
Author:
ben
Message:

Determine correct format for time_t.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openpgpsdk/trunk/configure

    r140 r167  
    44 
    55use Carp; 
     6use File::Temp; 
    67 
    78our %Subst=( 
     
    2728 
    2829my @Headers=qw(alloca.h); 
     30my @Types=qw(time_t); 
    2931 
    3032our %Knowledge=( 
    31                cc => sub { return chooseBinary('gcc','cc') 
     33               cc => sub { return chooseBinary('gcc','cc') 
    3234                             || croak 'Can\'t find C compiler'; }, 
    33                path => sub { return [split /:/,$ENV{PATH}]; }, 
     35                path => sub { return [split /:/,$ENV{PATH}]; }, 
     36                time_t => sub { return typeInfo('time_t','time.h'); } 
    3437              ); 
    3538 
     
    4548} 
    4649 
    47 my $os=`uname -s`; 
     50#my $os=`uname -s`; 
    4851 
    4952$Subst{'CC'}=getKnowledge('cc'); 
    5053 
    5154findHeaders(\@Headers); 
     55investigateTypes(\@Types); 
    5256 
    5357fixSubst(); 
     
    155159} 
    156160 
     161sub build { 
     162    my $code=shift; 
     163 
     164    my $cc=getKnowledge('cc'); 
     165    my $fh=new File::Temp(SUFFIX => '.c'); 
     166#    print $fh->filename(),"\n"; 
     167    print $fh $code; 
     168#    print $code; 
     169    $fh->close(); 
     170 
     171    my $cmd="$cc -Wall -Werror -c ".$fh; 
     172#    print "$cmd\n"; 
     173    my $ret=system("$cmd > /dev/null 2>&1"); 
     174 
     175    return $ret == 0; 
     176} 
     177 
     178sub typeInfo { 
     179    my $type=shift; 
     180    my $header=shift; 
     181 
     182    my %info; 
     183 
     184    print "Getting info about $type.\n"; 
     185 
     186    foreach my $fmt (qw(%d %ld)) { 
     187        my $code="#include <$header>\n"; 
     188        $code .= "#include <stdio.h>\n"; 
     189        $code .= "void f(void) { static $type t; printf(\"$fmt\",t); }\n"; 
     190        if(build($code)) { 
     191            $info{fmt}=$fmt; 
     192            print "  $type printf format is $fmt\n"; 
     193        } 
     194    } 
     195    croak "Can't determine print format for $type" if !defined $info{fmt}; 
     196 
     197    return \%info; 
     198} 
     199 
     200sub investigateTypes { 
     201    my $types=shift; 
     202 
     203    foreach my $type (@$types) { 
     204        my $info=getKnowledge($type); 
     205        $Subst{uc($type)."_FMT"}="\"$info->{fmt}\""; 
     206    } 
     207} 
     208 
  • openpgpsdk/trunk/examples/packet-dump.c

    r166 r167  
    22#include "packet-parse.h" 
    33#include "packet-show.h" 
     4#include "configure.h" 
    45#include "util.h" 
    56#include <unistd.h> 
     
    2021static void showtime(const unsigned char *name,time_t t) 
    2122    { 
    22     printf("%s=%ld (%.24s)",name,t,ctime(&t)); 
     23    printf("%s=" TIME_T_FMT " (%.24s)",name,t,ctime(&t)); 
    2324    } 
    2425 
     
    4546    print_indent(); 
    4647    printf("%s: ",name); 
    47     printf("duration %ld seconds",time); 
     48    printf("duration " TIME_T_FMT " seconds",time); 
    4849 
    4950    mins=time/60; 
  • openpgpsdk/trunk/include/configure.h.template

    r127 r167  
    11%HAVE_ALLOCA_H% 
     2#define TIME_T_FMT      %TIME_T_FMT%