diff options
-rw-r--r-- | contrib/lar/cli.c | 8 | ||||
-rw-r--r-- | contrib/lar/lar.c | 25 | ||||
-rw-r--r-- | contrib/lar/lar.h | 6 | ||||
-rwxr-xr-x | contrib/lar/lar.pl | 4 |
4 files changed, 26 insertions, 17 deletions
diff --git a/contrib/lar/cli.c b/contrib/lar/cli.c index e8daf63a53..098f55d9d6 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 <archive> [<member>]\n"); - printf("\tlar require <package>\n"); + printf("\tlar require <package> [<path>]\n"); return 1; } diff --git a/contrib/lar/lar.c b/contrib/lar/lar.c index 839b29299b..6bac9d6b82 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 59e6fa6209..04245ce632 100644 --- a/contrib/lar/lar.h +++ b/contrib/lar/lar.h @@ -7,14 +7,13 @@ #include <stdint.h> #include <fcntl.h> #include <string.h> +#include <errno.h> #include <arpa/inet.h> #include <sys/types.h> #include <sys/mman.h> #include <sys/stat.h> -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 56e4897958..2f9f3dd65f 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; } |