Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
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.
 
 
 
 

24 lines
679 B

  1. #include "fmt.h"
  2. /* "foo" -> "foo "
  3. * append padlen-srclen spaces after dest, if that is >= 0. Truncate
  4. * only if total length is larger than maxlen. Return number of
  5. * characters written. */
  6. size_t fmt_fill(char* dest,size_t srclen,size_t padlen,size_t maxlen) {
  7. long todo;
  8. char* olddest=dest;
  9. char* max=dest+maxlen;
  10. if ((long)padlen<0 || (long)maxlen<0) return 0;
  11. if (srclen>maxlen) return maxlen;
  12. if (dest==0) {
  13. unsigned long sum=srclen>padlen?srclen:padlen;
  14. return sum>maxlen?maxlen:sum;
  15. }
  16. dest+=srclen;
  17. for (todo=(long)(padlen-srclen); todo>0; --todo) {
  18. if (dest>max) break;
  19. *dest=' '; ++dest;
  20. }
  21. return (size_t)(dest-olddest);
  22. }