MCPcopy Create free account
hub / github.com/eggert/tz / timeout

Function timeout

date.c:185–212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

183}
184
185static void
186timeout(FILE *fp, char const *format, struct tm const *tmp)
187{
188 char *cp = NULL;
189 ptrdiff_t result;
190 ptrdiff_t size = 1024 / 2;
191
192 for ( ; ; ) {
193#ifdef ckd_mul
194 bool bigger = !ckd_mul(&size, size, 2) && size <= INDEX_MAX;
195#else
196 bool bigger = size <= INDEX_MAX / 2 && (size *= 2, true);
197#endif
198 char *newcp = bigger ? realloc(cp, size) : NULL;
199 if (!newcp) {
200 fprintf(stderr,
201 _("date: error: can't get memory\n"));
202 errensure();
203 exit(retval);
204 }
205 cp = newcp;
206 result = strftime(cp, size, format, tmp);
207 if (result != 0)
208 break;
209 }
210 fwrite(cp + 1, 1, result - 1, fp);
211 free(cp);
212}

Callers 1

displayFunction · 0.85

Calls 2

errensureFunction · 0.85
strftimeFunction · 0.85

Tested by

no test coverage detected