28#if __has_include(<unistd.h>)
36#include <sys/utsname.h>
49 *c = (
char *)malloc(
sizeof(name.nodename) +
sizeof(name.sysname) + 4);
50 strcpy(*c, name.nodename);
52 strcat(*c, name.sysname);
55 *c = (
char *)malloc(8);
56 strcpy(*c,
"unknown");
73 return ((ctty_pgrp = tcgetpgrp(STDOUT_FILENO)) != -1 && ctty_pgrp == pgrp);
83 struct winsize winsize;
85 if (
ioctl(fileno(
stdout), TIOCGWINSZ, &winsize) != -1)
86 return (winsize.ws_col ? winsize.ws_col : 80);
97 static int old_pos, next_print;
99 char buf[512], fmt[64];
100 int i,
j, ratio, barlength, remaining;
111 ratio = 100 * actual / max;
117 "Internal warning: progress_bar called with actual %i > max %i\n",
130 j = actual * (barlength - 1) / max;
131 if (
j > barlength || actual == max)
137 for (
i = old_pos + 1;
i <=
j;
i++)
138 if (
i * 100 / barlength >= next_print) {
139 printf(
"%1d", next_print / 10 % 10);
150 sprintf(buf,
"%d", max);
154 sprintf(fmt,
"\r[%%%dd/%%%dd]",
i,
i);
155 sprintf(buf, fmt, actual, max);
156 sprintf(buf + strlen(buf),
" %3d%%", ratio);
160 i = barlength * ratio / 100;
161 sprintf(buf + strlen(buf),
"|%.*s%*s|",
i,
162 "*******************************************************"
163 "*******************************************************"
164 "*******************************************************"
165 "*******************************************************"
166 "*******************************************************"
167 "*******************************************************"
168 "*******************************************************",
174 elapsed = now.tv_sec -
start.tv_sec;
176 if (elapsed <= 0.0 || actual <= 0) {
177 sprintf(buf + strlen(buf),
" --:-- ETA");
179 remaining = (int)(max / (actual / elapsed) - elapsed);
183 i = remaining / 3600;
185 sprintf(buf + strlen(buf),
"%4d:",
i);
187 sprintf(buf + strlen(buf),
" ");
188 i = remaining % 3600;
189 sprintf(buf + strlen(buf),
"%02d:%02d%s",
i / 60,
i % 60,
" ETA");
subroutine start()
start the timer (save starting time)
static int foreground_proc(void)
int gettimeofday(struct timeval *__restrict __tv, void *__restrict __tz) __attribute__((__nothrow__
int uname(struct utsname *__name) __attribute__((__nothrow__
int ioctl(int __fd, unsigned long int __request,...) __attribute__((__nothrow__
void progress_bar(int actual, int max)