Re: libelf question

2007-06-25 Thread Dag-Erling Smørgrav
Angus Barrow [EMAIL PROTECTED] writes:
 30   time_t timet=arh-ar_date;
 (gdb) n
 31   strftime(timestring, sizeof(timestring), %b %e %H:%M %Y,
 gmtime(timet));
 (gdb) n
 ...
 (gdb) print timet
 $1 = -1515870811

(gdb) p/x -1515870811
$1 = 0xa5a5a5a5

from malloc(3):

 J   Each byte of new memory allocated by malloc(), realloc() or
 reallocf() will be initialized to 0xa5.  All memory returned by
 free(), realloc() or reallocf() will be initialized to 0x5a.
 This is intended for debugging and will impact performance nega-
 tively.

DES
-- 
Dag-Erling Smørgrav - [EMAIL PROTECTED]
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


libelf question

2007-06-24 Thread Angus Barrow

Hi there,
   I'm trying to develop a BSD licensed version of the ar utility using
the new libelf library as this seems to be listed on the project ideas page
but doesn't seem to be being worked on.  I've started off simply trying to
get a toc printed for the archive but for some reason the time-stamp seems
to be coming back wrong for the contents of the archives.  The code in
question uses libelf to fetch a struct for each entry in an archive and it
prints out the data as a table:
 
...

Elf_Arhdr *arh;
while ((object = elf_begin(fd, ELF_C_READ, archive)) != NULL)
{
  if ((arh = elf_getarhdr(object)) == NULL)
 errx(EX_SOFTWARE, elf_getarhdr() failed: %s., elf_errmsg(-1));

  ...  
char timestring[20];

time_t timet=arh-ar_date;
strftime(timestring, sizeof(timestring), %b %e %H:%M %Y,
 gmtime(timet));

   The time shown in arh-ar_date (this is the struct that the libelf
library provides for each entry in the ar archive) seems to have a negative
value (using the GNU ar the date is Jun  3 13:09 2007, I've loaded the
program in gdb also and this seems to suggest the problem is with the
library:


30   time_t timet=arh-ar_date;
(gdb) n
31   strftime(timestring, sizeof(timestring), %b %e %H:%M %Y, 
gmtime(timet));

(gdb) n
...
(gdb) print timet
$1 = -1515870811
(gdb) print timestring
$2 = Dec 19 04:46 1921\000\000

   My question is, should I log a PR about this or is there something
obvious that I'm doing wrong here.  I'm totally new to writing anything
serious in C as all my uni courses use Java and VB.net etc.  Please find
the program attached in full.

Thanks for any advice.

Angus Barrow
#include err.h
#include libelf.h
#include stdio.h
#include string.h
#include sysexits.h
#include time.h
void prettyMode(int, char*);
int printToc(int fd, Elf *archive, int argc, char *argv, int VERBOSE_FLAG)
{
Elf *object;

printf((DBG)\tprint.c:printToc(Elf, char) - argc=%d verb=%d\n,argc, 
VERBOSE_FLAG);
Elf_Kind type = elf_kind(archive);
if(type!=ELF_K_AR)
errx(EX_DATAERR, Type of object is not ELF_K_AR\n);

Elf_Arhdr *arh;
while ((object = elf_begin(fd, ELF_C_READ, archive)) != NULL) {

if ((arh = elf_getarhdr(object)) == NULL)
errx(EX_SOFTWARE, elf_getarhdr() failed: %s., 
elf_errmsg(-1));

if(VERBOSE_FLAG!=1)
{
printf(%s\n, arh-ar_name);
} 
else
{
char timestring[20];
time_t timet=arh-ar_date;
strftime(timestring, sizeof(timestring), %b %e %H:%M 
%Y, gmtime(timet));

char perms[10]=-\0;

prettyMode(arh-ar_mode, perms);

printf(%s %u/%u %8u %s %s\n, perms, arh-ar_uid, 
arh-ar_gid, arh-ar_size, timestring, arh-ar_name);

}

elf_next(object);
elf_end(object);
}

elf_end(archive);

return 0;
}



void prettyMode(int mode, char *string)
{

/* There must be a better way or a library for this!*/

if(strlen(string)9)
{
printf(Urgh, that is not good!\nGive me a longer array!);
return;
}
if((mode  0400)==0400)
string[0]='r';
if((mode  0200)==0200)
string[1]='w';
if((mode  0100)==0100)
string[2]='x';

if((mode  040)==040)
string[3]='r';
if((mode  020)==020)
string[4]='w';
if((mode  010)==010)
string[5]='x';

if((mode  04)==04)
string[6]='r';
if((mode  02)==02)
string[7]='w';
if((mode  01)==01)
string[8]='x';




}
/*-
 * Copyright (c) 2007 Angus Barrow angus(at)aggyb.org
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *notice unmodified, this list of conditions, and the following
 *disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *notice, this list of conditions and the following disclaimer in the
 *documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, 

Re: libelf question

2007-06-24 Thread Tim Kientzle

Angus Barrow wrote:

   I'm trying to develop a BSD licensed version of the ar utility using
the new libelf library ...

   The time shown in arh-ar_date (this is the struct that the libelf
library provides for each entry in the ar archive) seems to have a negative
value (using the GNU ar the date is Jun  3 13:09 2007


Kai Wang recently added 'ar' support to libarchive/bsdtar;
what does 'tar -tv' say?

Note: You'll need a recent 7-CURRENT system for this
or you can install libarchive/bsdtar from the
most recent development snapshot on
http://people.freebsd.org/~kientzle/

Tim Kientzle
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]