Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
if(!infop->buffer)
return -1; /* fail */
infop->alloc = 32;
infop->len =0;
}
else if(infop->len+1 >= infop->alloc) {
char *newptr;
newptr = (char *)realloc(infop->buffer, infop->alloc*2);
if(!newptr) {
return -1;
}
infop->buffer = newptr;
infop->alloc *= 2;
}
infop->buffer[ infop->len ] = output;
infop->len++;
return output; /* fputc() returns like this on success */
}
char *curl_maprintf(const char *format, ...)
{
va_list ap_save; /* argument pointer */
int retcode;
struct asprintf info;
info.buffer = NULL;
info.len = 0;
info.alloc = 0;
va_start(ap_save, format);
retcode = dprintf_formatf(&info, alloc_addbyter, format, ap_save);
va_end(ap_save);
if(info.len) {
info.buffer[info.len] = 0; /* we terminate this with a zero byte */
return info.buffer;
}
else
return NULL;
}
char *curl_mvaprintf(const char *format, va_list ap_save)
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
{
int retcode;
struct asprintf info;
info.buffer = NULL;
info.len = 0;
info.alloc = 0;
retcode = dprintf_formatf(&info, alloc_addbyter, format, ap_save);
info.buffer[info.len] = 0; /* we terminate this with a zero byte */
if(info.len) {
info.buffer[info.len] = 0; /* we terminate this with a zero byte */
return info.buffer;
}
else
return NULL;
}
static int storebuffer(int output, FILE *data)
{
char **buffer = (char **)data;
**buffer = (char)output;
(*buffer)++;
return output; /* act like fputc() ! */
}
int curl_msprintf(char *buffer, const char *format, ...)
{
va_list ap_save; /* argument pointer */
int retcode;
va_start(ap_save, format);
retcode = dprintf_formatf(&buffer, storebuffer, format, ap_save);
va_end(ap_save);
*buffer=0; /* we terminate this with a zero byte */
return retcode;
}
#ifndef WIN32 /* not needed on win32 */
#endif
int curl_mprintf(const char *format, ...)
{
int retcode;
va_list ap_save; /* argument pointer */
va_start(ap_save, format);
retcode = dprintf_formatf(stdout, fputc, format, ap_save);
va_end(ap_save);
return retcode;
}
int curl_mfprintf(FILE *whereto, const char *format, ...)
{
int retcode;
va_list ap_save; /* argument pointer */
va_start(ap_save, format);
retcode = dprintf_formatf(whereto, fputc, format, ap_save);
va_end(ap_save);
return retcode;
}
int curl_mvsprintf(char *buffer, const char *format, va_list ap_save)
{
int retcode;
retcode = dprintf_formatf(&buffer, storebuffer, format, ap_save);
*buffer=0; /* we terminate this with a zero byte */
return retcode;
}
int curl_mvprintf(const char *format, va_list ap_save)
{
return dprintf_formatf(stdout, fputc, format, ap_save);
}
int curl_mvfprintf(FILE *whereto, const char *format, va_list ap_save)
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
{
return dprintf_formatf(whereto, fputc, format, ap_save);
}
#ifdef DPRINTF_DEBUG
int main()
{
char buffer[129];
char *ptr;
#ifdef SIZEOF_LONG_LONG
long long hullo;
dprintf("%3$12s %1$s %2$qd %4$d\n", "daniel", hullo, "stenberg", 65);
#endif
mprintf("%3d %5d\n", 10, 1998);
ptr=maprintf("test this then baby %s%s%s%s%s%s %d %d %d loser baby get a hit in yer face now!", "", "pretty long string pretty long string pretty long string pretty long string pretty long string", "/", "/", "/", "pretty long string", 1998, 1999, 2001);
puts(ptr);
memset(ptr, 55, strlen(ptr)+1);
free(ptr);
#if 1
mprintf(buffer, "%s %s %d", "daniel", "stenberg", 19988);
puts(buffer);
mfprintf(stderr, "%s %#08x\n", "dummy", 65);
printf("%s %#08x\n", "dummy", 65);
{
double tryout = 3.14156592;
mprintf(buffer, "%.2g %G %f %e %E", tryout, tryout, tryout, tryout, tryout);
puts(buffer);
printf("%.2g %G %f %e %E\n", tryout, tryout, tryout, tryout, tryout);
}
#endif
return 0;
}
#endif
/*
* local variables:
* eval: (load-file "../curl-mode.el")
* end:
* vim600: fdm=marker
* vim: et sw=2 ts=2 sts=2 tw=78