MCPcopy Create free account
hub / github.com/coreutils/coreutils / do_decode

Function do_decode

src/basenc.c:1561–1627  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1559}
1560
1561static _Noreturn void
1562do_decode (FILE *in, char const *infile, FILE *out, bool ignore_garbage)
1563{
1564 char *inbuf, *outbuf;
1565 idx_t sum;
1566 struct base_decode_context ctx;
1567
1568 inbuf = xmalloc (BASE_LENGTH (DEC_BLOCKSIZE));
1569 outbuf = xmalloc (DEC_BLOCKSIZE);
1570
1571#if BASE_TYPE == 42
1572 ctx.inbuf = NULL;
1573#endif
1574 base_decode_ctx_init (&ctx);
1575
1576 do
1577 {
1578 bool ok;
1579
1580 sum = 0;
1581 do
1582 {
1583 idx_t n = fread (inbuf + sum,
1584 1, BASE_LENGTH (DEC_BLOCKSIZE) - sum, in);
1585
1586 if (ignore_garbage)
1587 {
1588 for (idx_t i = 0; n > 0 && i < n;)
1589 {
1590 if (isubase (inbuf[sum + i])
1591 || (REQUIRED_PADDING (1) && inbuf[sum + i] == '='))
1592 i++;
1593 else
1594 memmove (inbuf + sum + i, inbuf + sum + i + 1, --n - i);
1595 }
1596 }
1597
1598 sum += n;
1599
1600 if (ferror (in))
1601 error (EXIT_FAILURE, errno, _("read error"));
1602 }
1603 while (sum < BASE_LENGTH (DEC_BLOCKSIZE) && !feof (in));
1604
1605 while (sum || feof (in))
1606 {
1607 idx_t n = DEC_BLOCKSIZE;
1608 if (sum)
1609 ok = base_decode_ctx (&ctx, inbuf, sum, outbuf, &n);
1610 else
1611 ok = base_decode_ctx_finalize (&ctx, &outbuf, &n);
1612
1613 if (fwrite (outbuf, 1, n, out) < n)
1614 write_error ();
1615
1616 if (! ok)
1617 error (EXIT_FAILURE, 0, _("invalid input"));
1618

Callers 1

mainFunction · 0.85

Calls 2

write_errorFunction · 0.85
finish_and_exitFunction · 0.85

Tested by

no test coverage detected