stdarg.c 353 B

12345678910111213141516171819
  1. /* copied from rsync */
  2. #include <sys/types.h>
  3. #include <stdarg.h>
  4. void foo(const char *format, ...) {
  5. va_list ap;
  6. int len;
  7. char buf[5];
  8. va_start(ap, format);
  9. len = vsnprintf(0, 0, format, ap);
  10. va_end(ap);
  11. if (len != 5) exit(1);
  12. if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(1);
  13. exit(0);
  14. }
  15. int main() { foo("hello"); }