autoconf
[Top][All Lists]
Advanced

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

Re: AC_CHECK_FILES on /dev/stdin


From: David Fang
Subject: Re: AC_CHECK_FILES on /dev/stdin
Date: Thu, 30 Mar 2006 20:53:16 -0500 (EST)

> Whether /dev/std{in,out,err} are devices, symlinks, or even present
> is going to be system dependent.
>
> They're real character devices on NetBSD:
> $ ls -l /dev/std{in,out,err}
> crw-rw-rw-  1 root  wheel  22, 2 Feb 19 11:01 /dev/stderr
> crw-rw-rw-  1 root  wheel  22, 0 Feb 19 11:01 /dev/stdin
> crw-rw-rw-  1 root  wheel  22, 1 Feb 19 11:01 /dev/stdout
>
> And while they're symlinks on Solaris, they're not to /proc:
> $ ls -l /dev/std{in,out,err}
> lrwxrwxrwx   1 root     root           6 Nov 21 09:15 /dev/stderr -> ./fd/2
> lrwxrwxrwx   1 root     root           6 Nov 21 09:15 /dev/stdin -> ./fd/0
> lrwxrwxrwx   1 root     root           6 Nov 21 09:15 /dev/stdout -> ./fd/1

Right, but fortunately, for my particular use, it doesn't matter *how*
they look in the file system.

> > You don't need to check for them.  Unless you explicitly force it to
> > be otherwise, *every* process is *guaranteed* to have stdin, stdout
> > and stderr streams;  you must be doing something very esoteric, if
> > you find a need to refer to /dev/stdin, /dev/stdout or /dev/stderr.
>
> It depends on why David is checking for them.
>
> For example, one reason you might want to is to ensure a program works
> with /dev/std{in,out,err} when specified as a command line argument as
> an input/output filename even if the OS does not have native support
> for /dev/std{in,out,err}.  I know I've seen this somewhere, but I
> can't recall where off hand.

As I said in the other message, I just need to see if it is openable and
usable with std::ifstream, so I've devised the following test.  Does this
look reasonable?


dnl
dnl Category: C++
dnl Checks to see if std::ifstream can open "/dev/stdin"
dnl AC_DEFINEs HAVE_STD_IFSTREAM_DEV_STDIN if successful.
dnl
AC_DEFUN([AC_CXX_STD_IFSTREAM_DEV_STDIN],
[AC_REQUIRE([AC_PROG_CXX])
AC_CACHE_CHECK(
        [whether std::ifstream works with /dev/stdin],
        [ac_cv_cxx_std_ifstream_dev_stdin],
[AC_LANG_PUSH(C++)
dnl default/initially no
ac_cv_cxx_std_ifstream_dev_stdin=no
AC_LINK_IFELSE(
        AC_LANG_PROGRAM([[
                #include <iostream>
                #include <fstream>
                #include <string>
                using namespace std;
        ]], [[
                ifstream fcin("/dev/stdin");
                if (fcin) {
                        string line;
                        while (getline(fcin, line)) {
                                cout << line << endl;
                        }
                } else {
                        cout << "You lose." << endl;
                }
        ]]),
        [echo "Hello, world!" > conftest.in
        echo "That's all, folks!" >> conftest.in
        ./conftest$ac_exeext < conftest.in > conftest.out 2>&1
        if diff conftest.in conftest.out > /dev/null 2>&1
        then
                ac_cv_cxx_std_ifstream_dev_stdin=yes
        fi
        rm -f conftest.in conftest.out
        ],
        []
)
AC_LANG_POP(C++)
])
if test "$ac_cv_cxx_std_ifstream_dev_stdin" = yes ; then
AC_DEFINE(HAVE_STD_IFSTREAM_DEV_STDIN, [],
        [Define if std::ifstream(/dev/stdin) works])
fi
])

dnl End of macro.


David





reply via email to

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