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.
 
 
 
 

43 lines
684 B

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