diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2009-04-06 22:58:44 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2009-04-06 22:58:44 +0000 |
commit | acf5ea72c70ddbdb90b18a2ae1169ad82e455876 (patch) | |
tree | 072cc1d19061f8e557726a6c8a3efd04c2c072d1 /contrib/lar/lar.c | |
parent | bf1cbdd8389d5e7067b03c1f10e9fbcb3756ccf4 (diff) |
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
Diffstat (limited to 'contrib/lar/lar.c')
-rw-r--r-- | contrib/lar/lar.c | 25 |
1 files changed, 18 insertions, 7 deletions
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); |