Skip to content

Commit

Permalink
don't close standard out
Browse files Browse the repository at this point in the history
  • Loading branch information
N-R-K committed Jan 30, 2025
1 parent c6f9138 commit 0984807
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/scrot.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,12 @@ static void scrotGrabMousePointer(Imlib_Image image, const int xOffset,

static int scrotCheckIfOverwriteFile(char **filename)
{
if (strcmp(*filename, "-") == 0)
return 1;
if (strcmp(*filename, "-") == 0) {
int fd = dup(1); // scrotSaveImage will close the fd, so dup it
if (fd < 0)
err(EXIT_FAILURE, "dup failed");
return fd;
}

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

0 comments on commit 0984807

Please sign in to comment.