G
goldfita
I'm not sure if I'm doing something stupid, or if I'm not understanding
how to use variadic functions. These functions appear to be working
individually. In ast_call, I can vprintf the argument list and it
looks fine. If I invoke write_cmd, it seems to work fine. But when I
invoke write_cmd in ast_call with argp, I get garbage in argp in
write_cmd. I don't know where it's breaking.
int ast_call(struct ast_connection *conn, char *msg, ...)
{
va_list argp;
va_start(argp,msg);
if(!write_cmd(conn->socket,msg,argp)) {
va_end(argp);
return write_FAIL;
}
va_end(argp);
if(!conn->params.wait_for_resp)
return AST_SUCCESS;
return ast_wait_peek_by_id(conn,conn->cnt++);
}
static int write_cmd(int socket, char *msg, ...)
{
int n=0,len=0,slen;
va_list argp;
char buf[BUFSIZE];
va_start(argp,msg);
vsprintf(buf,msg,argp);
va_end(argp);
slen = strlen(buf);
puts(buf);
for(len=0; len<slen {
if((n = write(socket,buf+len,slen-len)) < 0)
return 0;
len += n;
}
return 1;
}
how to use variadic functions. These functions appear to be working
individually. In ast_call, I can vprintf the argument list and it
looks fine. If I invoke write_cmd, it seems to work fine. But when I
invoke write_cmd in ast_call with argp, I get garbage in argp in
write_cmd. I don't know where it's breaking.
int ast_call(struct ast_connection *conn, char *msg, ...)
{
va_list argp;
va_start(argp,msg);
if(!write_cmd(conn->socket,msg,argp)) {
va_end(argp);
return write_FAIL;
}
va_end(argp);
if(!conn->params.wait_for_resp)
return AST_SUCCESS;
return ast_wait_peek_by_id(conn,conn->cnt++);
}
static int write_cmd(int socket, char *msg, ...)
{
int n=0,len=0,slen;
va_list argp;
char buf[BUFSIZE];
va_start(argp,msg);
vsprintf(buf,msg,argp);
va_end(argp);
slen = strlen(buf);
puts(buf);
for(len=0; len<slen {
if((n = write(socket,buf+len,slen-len)) < 0)
return 0;
len += n;
}
return 1;
}