> printf("Disk size:\t\t%*s\n", width, > df_pretty_sizes(total_disk, mode)); > > it would be translated (note the '%*s'): > > if (mode == DF_HUMAN_UNIT) > printf("Disk size:\t\t%*s%s\n", width-2, > df_pretty_sizes_number(total_disk), > df_pretty_sizes_unit(total_disk)); > else > printf("Disk size:\t\t%*lld\n", width, total_disk);
So use mode as the argument in the second case, just like you did in the first. printf("Disk dize:\t\t"sz_fmt"\n", sz_arg(total_disk, mode, width)); #define sz_fmt "%*llu%s" #define sz_fmt(v,m,w) width(w, m), scaled(v, m), units(v, m) And again, the reason we jump through these mildly distasteful hoops is that *it gets rid of allocated strings entirely*. That bug in df_pretty_sizes() where it allocates a 20 byte buffer to store a string that can be 21 bytes long with its null? It'd just vanish. Not needed. The only code that is *sure* to be bug free is the code that doesn't exist. > To avoid all this mess, we should add another conversion specifier with > the function register_printf_function(). Unfortunately I was not able to > find the equivalent one for sprintf(). Doesn't that prevent compile-time verification that the types of the format specifiers match the arguments? - z -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html