fix: fflush(stdout), should sort out the blocking pipe problem

add:  line length (@merlokk)
This commit is contained in:
Chris 2018-11-02 18:27:42 +01:00
commit d30454fc5a
3 changed files with 18 additions and 19 deletions

View file

@ -25,23 +25,20 @@ void PrintAndLogOptions(char *str[][2], size_t size, size_t space) {
char buff[2000] = "Options:\n";
char format[2000] = "";
size_t counts[2] = {0, 0};
for(int i = 0; i < size; i++)
for(int j = 0 ; j < 2 ; j++)
if(counts[j] < strlen(str[i][j]))
{
for (int i = 0; i < size; i++)
for (int j = 0 ; j < 2 ; j++)
if (counts[j] < strlen(str[i][j])) {
counts[j] = strlen(str[i][j]);
}
for(int i = 0; i < size; i++)
{
for(int j = 0; j < 2; j++)
{
if(j == 0)
for (int i = 0; i < size; i++) {
for (int j = 0; j < 2; j++) {
if (j == 0)
snprintf(format, sizeof(format), "%%%zus%%%zus", space, counts[j]);
else
snprintf(format, sizeof(format), "%%%zus%%-%zus", space, counts[j]);
snprintf(buff + strlen(buff), sizeof(buff) - strlen(buff), format, " ", str[i][j]);
}
if(i<size-1)
if (i < size-1)
strncat(buff, "\n", sizeof(buff)-strlen(buff) -1);
}
PrintAndLogEx(NORMAL, buff);
@ -178,7 +175,7 @@ void PrintAndLog(char *fmt, ...) {
va_end(argptr2);
if (flushAfterWrite)
fflush(NULL);
fflush(stdout);
//release lock
pthread_mutex_unlock(&print_lock);