My slstatus configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

42 lines
651 B

  1. /* See LICENSE file for copyright and license details. */
  2. #include <stdarg.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "util.h"
  6. const char *
  7. bprintf(const char *fmt, ...)
  8. {
  9. va_list ap;
  10. size_t len;
  11. va_start(ap, fmt);
  12. len = vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
  13. va_end(ap);
  14. if (len >= sizeof(buf))
  15. buf[sizeof(buf)-1] = '\0';
  16. return buf;
  17. }
  18. int
  19. pscanf(const char *path, const char *fmt, ...)
  20. {
  21. FILE *fp;
  22. va_list ap;
  23. int n;
  24. if (!(fp = fopen(path, "r"))) {
  25. fprintf(stderr, "fopen for %s failed", path);
  26. return -1;
  27. }
  28. va_start(ap, fmt);
  29. n = vfscanf(fp, fmt, ap);
  30. va_end(ap);
  31. fclose(fp);
  32. return (n == EOF) ? -1 : n;
  33. }