From acf5ea72c70ddbdb90b18a2ae1169ad82e455876 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 6 Apr 2009 22:58:44 +0000 Subject: contrib/lar: - fix short read of index table - properly handle errno by using errno.h - extend lar_find_archive() to take a base search path a second argument - extend cli.c to allow specifing the base search path - print index number in lar.pl --- contrib/lar/cli.c | 8 ++++---- contrib/lar/lar.c | 25 ++++++++++++++++++------- contrib/lar/lar.h | 6 ++---- contrib/lar/lar.pl | 4 ++-- 4 files changed, 26 insertions(+), 17 deletions(-) (limited to 'contrib') diff --git a/contrib/lar/cli.c b/contrib/lar/cli.c index e8daf63a5..098f55d9d 100644 --- a/contrib/lar/cli.c +++ b/contrib/lar/cli.c @@ -30,13 +30,13 @@ int do_print_index( lar_archive *ar ) return 0; } -int do_require( const char *package ) +int do_require( const char *package, const char *path ) { int stat = 1; lar_archive *ar; lar_member *mb; - if( (ar = lar_find_archive(package)) != NULL ) + if( (ar = lar_find_archive(package, path)) != NULL ) { if( (mb = lar_find_member(ar, package)) != NULL ) { @@ -78,7 +78,7 @@ int main( int argc, const char* argv[] ) break; case 'r': - stat = do_require(argv[2]); + stat = do_require(argv[2], argv[3]); break; } @@ -88,7 +88,7 @@ int main( int argc, const char* argv[] ) { printf("Usage:\n"); printf("\tlar show []\n"); - printf("\tlar require \n"); + printf("\tlar require []\n"); return 1; } diff --git a/contrib/lar/lar.c b/contrib/lar/lar.c index 839b29299..6bac9d6b8 100644 --- a/contrib/lar/lar.c +++ b/contrib/lar/lar.c @@ -46,7 +46,7 @@ lar_index * lar_get_index( lar_archive *ar ) idx_map = NULL; for( i = 0; i < idx_length; \ - i += (sizeof(lar_index) - sizeof(char)) + i += (sizeof(lar_index) - sizeof(char *)) ) { idx_ptr = (lar_index *)malloc(sizeof(lar_index)); @@ -174,16 +174,27 @@ int lar_close( lar_archive *ar ) return 0; } -lar_archive * lar_find_archive( const char *package ) +lar_archive * lar_find_archive( const char *package, const char *path ) { int seg = 1; - int i, j, len; + int len = 0; + int pln = 0; + int i, j; struct stat s; LAR_FNAME(buffer); + if( path ) + { + for( pln = 0; path[pln] != '\0'; pln++ ) + if( pln >= (sizeof(buffer) - 5) ) + LAR_DIE("Library path exceeds maximum allowed length"); + + memcpy(buffer, path, pln); + } + for( len = 0; package[len] != '\0'; len++ ) { - if( len >= (sizeof(buffer) - 5) ) + if( len >= (sizeof(buffer) - 5 - pln) ) LAR_DIE("Package name exceeds maximum allowed length"); if( package[len] == '.' ) seg++; @@ -197,11 +208,11 @@ lar_archive * lar_find_archive( const char *package ) if( j < seg ) j++; else break; } - buffer[i] = ( package[i] == '.' ) ? LAR_DIRSEP : package[i]; + buffer[pln+i] = ( package[i] == '.' ) ? LAR_DIRSEP : package[i]; } - buffer[i+0] = '.'; buffer[i+1] = 'l'; buffer[i+2] = 'a'; - buffer[i+3] = 'r'; buffer[i+4] = '\0'; + buffer[pln+i+0] = '.'; buffer[pln+i+1] = 'l'; buffer[pln+i+2] = 'a'; + buffer[pln+i+3] = 'r'; buffer[pln+i+4] = '\0'; if( (stat(buffer, &s) > -1) && (s.st_mode & S_IFREG) ) return lar_open(buffer); diff --git a/contrib/lar/lar.h b/contrib/lar/lar.h index 59e6fa620..04245ce63 100644 --- a/contrib/lar/lar.h +++ b/contrib/lar/lar.h @@ -7,14 +7,13 @@ #include #include #include +#include #include #include #include #include -int errno; - #define LAR_DIE(s) \ do { \ fprintf(stderr, "%s(%i): %s(): %s\n", \ @@ -82,9 +81,8 @@ lar_archive * lar_open( const char *filename ); int lar_close( lar_archive *ar ); -lar_archive * lar_find_archive( const char *package ); +lar_archive * lar_find_archive( const char *package, const char *path ); lar_member * lar_find_member( lar_archive *ar, const char *package ); #endif - diff --git a/contrib/lar/lar.pl b/contrib/lar/lar.pl index 56e489795..2f9f3dd65 100755 --- a/contrib/lar/lar.pl +++ b/contrib/lar/lar.pl @@ -38,10 +38,10 @@ foreach my $file ( @ARGV ) } } - +my $count = 1; foreach my $file ( @index ) { - warn sprintf "Index: 0x%08X 0x%08X 0x%08X 0x%08X\n", $file->[0], $file->[1], $file->[2], $file->[3]; + warn sprintf "Index[%4d]: 0x%08X 0x%08X 0x%08X 0x%08X\n", $count++, $file->[0], $file->[1], $file->[2], $file->[3]; print pack "NNNNnn", $file->[0], $file->[1], $file->[2], $file->[3], 0x0000, 0x0000; } -- cgit v1.2.3