Tests: Fix memory leaks in test_block_header.
[xz/debian.git] / src / common / tuklib_mbstr_fw.c
blob64c9ad5ae37245ca3a06d2da052d7c8e4bda697e
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file tuklib_mbstr_fw.c
4 /// \brief Get the field width for printf() e.g. to align table columns
5 //
6 // Author: Lasse Collin
7 //
8 // This file has been put into the public domain.
9 // You can do whatever you want with this file.
11 ///////////////////////////////////////////////////////////////////////////////
13 #include "tuklib_mbstr.h"
16 extern int
17 tuklib_mbstr_fw(const char *str, int columns_min)
19 size_t len;
20 const size_t width = tuklib_mbstr_width(str, &len);
21 if (width == (size_t)-1)
22 return -1;
24 if (width > (size_t)columns_min)
25 return 0;
27 if (width < (size_t)columns_min)
28 len += (size_t)columns_min - width;
30 return (int)len;