Skip to content

Commit 53b5edf

Browse files
committed
don't close standard out
1 parent c6f9138 commit 53b5edf

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/scrot.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,13 @@ static void scrotGrabMousePointer(Imlib_Image image, const int xOffset,
542542

543543
static int scrotCheckIfOverwriteFile(char **filename)
544544
{
545-
if (strcmp(*filename, "-") == 0)
546-
return 1;
545+
if (strcmp(*filename, "-") == 0) {
546+
// scrotSaveImage will close the fd, so dup it
547+
int fd = fcntl(1, F_DUPFD_CLOEXEC, 3);
548+
if (fd < 0)
549+
err(EXIT_FAILURE, "dup failed");
550+
return fd;
551+
}
547552

548553
int flags = O_RDWR | O_CREAT | (opt.overwrite ? O_TRUNC : O_EXCL);
549554
int fd = open(*filename, flags, 0644);

0 commit comments

Comments
 (0)