/* Formatted output to obstacks.
- Copyright (C) 2008 Free Software Foundation, Inc.
+ Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
stack-allocated buffer and copy, to reduce the likelihood of a
small-size malloc. Otherwise, print directly into the
obstack. */
- const size_t cutoff = 1024;
- char buf[cutoff];
+ enum { CUTOFF = 1024 };
+ char buf[CUTOFF];
char *base = obstack_next_free (obs);
size_t len = obstack_room (obs);
char *str;
- if (len < cutoff)
+ if (len < CUTOFF)
{
base = buf;
- len = cutoff;
+ len = CUTOFF;
}
str = vasnprintf (base, &len, format, args);
if (!str)
{
if (errno == ENOMEM)
- obstack_alloc_failed_handler ();
+ obstack_alloc_failed_handler ();
return -1;
}
if (str == base && str != buf)
else
{
/* The output exceeded available obstack space or we used buf;
- copy the resulting string. */
+ copy the resulting string. */
obstack_grow (obs, str, len);
if (str != buf)
- free (str);
+ free (str);
}
return len;
}