[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#24599: Cannot process files named -

From: João Miguel
Subject: bug#24599: Cannot process files named -
Date: Mon, 3 Oct 2016 19:12:59 +0100

Good afternoon,

As I was trying to reimplement the coreutils in Haskell (for fun :D), I
noticed that many commands (such as "cat -- -") will disregard the --
and try to read the stdin.

I initially thought this was not a bug (found no report about this in
these mailing lists while searching for «file named ""-""»), but it
works as expected with vi ("vi -" tries to read stdin, "vi -- -" edits
the file named -).

Looking through the source code (of "cat" in this case, because it's
simpler), "-" is not taken to be an option (it's not possible with the
way Getopt works in Haskell, seems it's not possible in C either - is
adding "{NULL, no_argument, NULL, '\0'}" to long_options possible? I
don't really know C...). But it can be worked around, here (lines 663 to

   if (STREQ (infile, "-"))   // should add "&& noopt_was_passed"
       have_read_stdin = true;
       input_desc = STDIN_FILENO;
       if ((file_open_mode & O_BINARY) && ! isatty (STDIN_FILENO))
         xfreopen (NULL, "rb", stdin);

an extra check for "--" could be added (in Haskell this would require
checking *before* the arguments were passed to getopt, probably the same
applies to C).

I've seen this behaviour in "cut" as well, and other programs, as this
seems to show:
  $ pwd
  $ grep 'if (STREQ.*"-")' -R . | cut -f1 -d' ' | uniq | sed -e
's#\./##' -e 's#:##' | tr '\n' ' '
 stat.c cut.c tail.c shred.c unexpand.c od.c nl.c sort.c touch.c
 date.c fold.c expand.c pr.c wc.c fmt.c base64.c cksum.c cat.c paste.c 

Hoping you can reply soon (not subscribed),
João Miguel

reply via email to

[Prev in Thread] Current Thread [Next in Thread]