/* Don't copy a file to itself if that would merely exhaust the
output device. It's better to catch this error earlier
rather than later. */
if (! (S_ISFIFO (istat_buf.st_mode) || S_ISSOCK (istat_buf.st_mode)
|| S_TYPEISSHM (&istat_buf) || S_TYPEISTMO (&istat_buf))
&& ! (S_TYPEISSHM (&ostat_buf) || S_TYPEISTMO (&ostat_buf))
&& SAME_INODE (istat_buf, ostat_buf))
{
off_t in_pos = lseek (input_desc, 0, SEEK_CUR);
if (0 <= in_pos)
{
if (out_flags < -1)
out_flags = fcntl (STDOUT_FILENO, F_GETFL);
int whence = (0 <= out_flags && out_flags & O_APPEND
? SEEK_END : SEEK_CUR);
if (in_pos < lseek (STDOUT_FILENO, 0, whence))
{
error (0, 0, _("%s: input file is output file"),
quotef (infile));
ok = false;
goto contin;
}
}
}
/* Pointer to the input buffer. */
char *inbuf;
/* Select which version of 'cat' to use. If any format-oriented
options were given use 'cat'; if not, use 'copy_cat' if it
works, 'simple_cat' otherwise. */
if (! (number || show_ends || show_nonprinting
|| show_tabs || squeeze_blank))
{
int copy_cat_status =
out_isreg && S_ISREG (istat_buf.st_mode) ? copy_cat () : 0;
if (copy_cat_status != 0)
{
inbuf = NULL;
ok &= 0 < copy_cat_status;
}
else
{
insize = MAX (insize, outsize);
inbuf = xalignalloc (page_size, insize);
ok &= simple_cat (inbuf, insize);
}
}
else
{
/* Allocate, with an extra byte for a newline sentinel. */
inbuf = xalignalloc (page_size, insize + 1);
/* Why are
(OUTSIZE - 1 + INSIZE * 4 + LINE_COUNTER_BUF_LEN)
bytes allocated for the output buffer?
A test whether output needs to be written is done when the input
buffer empties or when a newline appears in the input. After
output is written, at most (OUTSIZE - 1) bytes will remain in the
buffer. Now INSIZE bytes of input is read. Each input character
may grow by a factor of 4 (by the prepending of M-^). If all
characters do, and no newlines appear in this block of input, we
will have at most (OUTSIZE - 1 + INSIZE * 4) bytes in the buffer.
If the last character in the preceding block of input was a
newline, a line number may be written (according to the given
options) as the first thing in the output buffer. (Done after the
new input is read, but before processing of the input begins.)
A line number requires seldom more than LINE_COUNTER_BUF_LEN
positions.
Align the output buffer to a page size boundary, for efficiency
on some paging implementations. */
idx_t bufsize;
if (ckd_mul (&bufsize, insize, 4)
|| ckd_add (&bufsize, bufsize, outsize)
|| ckd_add (&bufsize, bufsize, LINE_COUNTER_BUF_LEN - 1))
xalloc_die ();
char *outbuf = xalignalloc (page_size, bufsize);
ok &= cat (inbuf, insize, outbuf, outsize, show_nonprinting,
show_tabs, number, number_nonblank, show_ends,
squeeze_blank);
alignfree (outbuf);
}
alignfree (inbuf);
contin:
if (!reading_stdin && close (input_desc) < 0)
{
error (0, errno, "%s", quotef (infile));
ok = false;
}
}
while (++argind < argc);
if (pending_cr)
{
if (full_write (STDOUT_FILENO, "\r", 1) != 1)
write_error ();
}
if (have_read_stdin && close (STDIN_FILENO) < 0)
error (EXIT_FAILURE, errno, _("closing standard input"));
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
🍓2
just discovered a new kool upcoming feature in kde plasma: hiding individual windows from screen recordings/shares
👍15🥰6❤3💋2🔥1🍓1 1 1
Forwarded from bero
меня накормили клубничкой в фубаре так что ещё не всё потеряно
🍓16❤1
Forwarded from Dumer Mexan
Наконец то девстд стал снова про дев стд, а не бну крл кот и прн
❤7🍓2
Forwarded from So far, so good (Νέκιτ)
This media is not supported in your browser
VIEW IN TELEGRAM