X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=common-src%2Fpacket.c;h=bbeb7816fccc45b190336b49f107b02a0681b955;hb=691567b16c13087b31ee4c2b6d038e57872fae82;hp=7ebda6173d69cf7bc4c2013b5a289cfc2d712a5a;hpb=cdbbeef9cde260e429854dd313bc0bf7560e1e24;p=debian%2Famanda diff --git a/common-src/packet.c b/common-src/packet.c index 7ebda61..bbeb781 100644 --- a/common-src/packet.c +++ b/common-src/packet.c @@ -1,6 +1,7 @@ /* * Amanda, The Advanced Maryland Automatic Network Disk Archiver * Copyright (c) 1991-1999 University of Maryland at College Park + * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved. * All Rights Reserved. * * Permission to use, copy, modify, distribute, and sell this software and its @@ -50,26 +51,44 @@ static const struct { /* * Initialize a packet */ +void pkt_init_empty( + pkt_t *pkt, + pktype_t type) +{ + assert(pkt != NULL); + assert(strcmp(pkt_type2str(type), "BOGUS") != 0); + + pkt->type = type; + pkt->packet_size = 1000; + pkt->body = alloc(pkt->packet_size); + pkt->body[0] = '\0'; + pkt->size = strlen(pkt->body); +} + printf_arglist_function2(void pkt_init, pkt_t *, pkt, pktype_t, type, const char *, fmt) { va_list argp; + int len; assert(pkt != NULL); assert(strcmp(pkt_type2str(type), "BOGUS") != 0); - assert(fmt != NULL); + if(fmt == NULL) + fmt = ""; pkt->type = type; pkt->packet_size = 1000; pkt->body = alloc(pkt->packet_size); - arglist_start(argp, fmt); - while (vsnprintf(pkt->body, pkt->packet_size, fmt, argp) >= - (int)(pkt->packet_size - 1)) { + while(1) { + arglist_start(argp, fmt); + len = g_vsnprintf(pkt->body, pkt->packet_size, fmt, argp); + arglist_end(argp); + if (len > -1 && len < (int)(pkt->packet_size - 1)) + break; pkt->packet_size *= 2; amfree(pkt->body); pkt->body = alloc(pkt->packet_size); } - arglist_end(argp); pkt->size = strlen(pkt->body); } @@ -79,6 +98,7 @@ printf_arglist_function2(void pkt_init, pkt_t *, pkt, pktype_t, type, printf_arglist_function1(void pkt_cat, pkt_t *, pkt, const char *, fmt) { size_t len; + int lenX; va_list argp; char * pktbody; @@ -87,19 +107,19 @@ printf_arglist_function1(void pkt_cat, pkt_t *, pkt, const char *, fmt) len = strlen(pkt->body); - arglist_start(argp, fmt); - while (vsnprintf(pkt->body + len, pkt->packet_size - len, fmt,argp) >= - (int)(pkt->packet_size - len - 1)) { + while(1) { + arglist_start(argp, fmt); + lenX = g_vsnprintf(pkt->body + len, pkt->packet_size - len, fmt,argp); + arglist_end(argp); + if (lenX > -1 && lenX < (int)(pkt->packet_size - len - 1)) + break; pkt->packet_size *= 2; pktbody = alloc(pkt->packet_size); strncpy(pktbody, pkt->body, len); pktbody[len] = '\0'; amfree(pkt->body); pkt->body = pktbody; - arglist_end(argp); - arglist_start(argp, fmt); } - arglist_end(argp); pkt->size = strlen(pkt->body); }