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.
 
 
 
 

44 lines
689 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. }
  18. return buf;
  19. }
  20. int
  21. pscanf(const char *path, const char *fmt, ...)
  22. {
  23. FILE *fp;
  24. va_list ap;
  25. int n;
  26. if (!(fp = fopen(path, "r"))) {
  27. fprintf(stderr, "fopen '%s': %s\n", path, strerror(errno));
  28. return -1;
  29. }
  30. va_start(ap, fmt);
  31. n = vfscanf(fp, fmt, ap);
  32. va_end(ap);
  33. fclose(fp);
  34. return (n == EOF) ? -1 : n;
  35. }