Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could make an autoconf test, if you're using autotools for your buildsystem.</p> <pre><code>AC_LANG([C]) AC_USE_SYSTEM_EXTENSIONS AC_ARG_WITH([dprintf], [AS_HELP_STRING([--with-dprintf], [Assume that dprintf prints to a specified file descriptor])], [], [with_dprintf=check]) AS_IF([test "x$with_dprintf" = xcheck], [AC_RUN_IFELSE( [AC_LANG_PROGRAM([[ #include &lt;stdio.h&gt; #include &lt;string.h&gt; int debug_level; ]], [[ char msg[] = "Hello, world!\n"; char rcv[sizeof(msg)] = ""; FILE *f = tmpfile(); int fd = fileno(f); debug_level = fd - 1; dprintf(fd, "%s", msg); fseek(f, 0, SEEK_SET); fread(rcv, 1, sizeof(msg), f); return strcmp(msg, rcv); ]] )], [with_dprintf=yes])]) AS_IF([test "x$with_dprintf" = xyes], [AC_DEFINE([HAVE_DPRINTF], [1], [dprintf prints to a specified file descriptor])]) </code></pre> <p>(Allowing for <code>--with-dprintf</code> or <code>--without-dprintf</code> when cross-compiling, as <code>AC_RUN_IFELSE</code> isn't valid in those cases.)</p> <hr> <p><a href="http://opengroup.org/onlinepubs/007908775/xsh/fdopen.html" rel="nofollow noreferrer">fdopen</a> isn't in standard C, but it <em>is</em> in POSIX.2 and later. I don't recall any UNIX-like that doesn't have it -- heck, even Windows has it.</p> <pre><code>int fdprintf(int fd, char *fmt, ...) { va_list ap; FILE *f = fdopen(fd); int rc; va_start(ap, &amp;fmt); rc = vfprintf(f, fmt, ap); fclose(f); va_end(ap); return rc; } </code></pre> <p>Of course, if you know which file descriptor you'll be printing to, just keep the <code>FILE*</code> pointer around instead.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload