stdarg.c 431 B

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