Handle very long port names.

This commit is contained in:
Jonathan Moore Liles 2008-07-21 23:36:29 -05:00
parent 00aeaff29b
commit d490e88707
2 changed files with 16 additions and 3 deletions

View File

@ -31,6 +31,12 @@ static const char *name_for_port ( Port::type_e dir, const char *base, int n, co
int
Port::max_name ( void )
{
return jack_port_name_size() - jack_client_name_size() - 6;
}
/* nframes is the number of frames to buffer */ /* nframes is the number of frames to buffer */
Port::Port ( jack_port_t *port ) Port::Port ( jack_port_t *port )
{ {
@ -62,14 +68,19 @@ Port::~Port ( )
static const char * static const char *
name_for_port ( Port::type_e dir, const char *base, int n, const char *type ) name_for_port ( Port::type_e dir, const char *base, int n, const char *type )
{ {
static char pname[256]; static char pname[ 512 ];
const char *dir_s = dir == Port::Output ? "out" : "in"; const char *dir_s = dir == Port::Output ? "out" : "in";
strncpy( pname, base, Port::max_name() );
pname[ Port::max_name() - 1 ] = '\0';
int l = strlen( pname );
if ( type ) if ( type )
snprintf( pname, sizeof( pname ), "%s/%s-%s-%d", base, type, dir_s, n + 1 ); snprintf( pname + l, sizeof( pname ) - l, "/%s-%s-%d", type, dir_s, n + 1 );
else else
snprintf( pname, sizeof( pname ), "%s/%s-%d", base, dir_s, n + 1 ); snprintf( pname + l, sizeof( pname ) - l, "/%s-%d", dir_s, n + 1 );
return pname; return pname;
} }

View File

@ -38,6 +38,8 @@ public:
enum type_e { Output, Input }; enum type_e { Output, Input };
static int max_name ( void );
Port ( jack_port_t *port ); Port ( jack_port_t *port );
Port ( const char *name, type_e dir ); Port ( const char *name, type_e dir );
Port ( type_e dir, const char *base, int n, const char *type=0 ); Port ( type_e dir, const char *base, int n, const char *type=0 );