From 9e74a91806a5615f2f21cfff2ac0daddfbe80f90 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 3 Sep 2016 15:57:11 -0400 Subject: Track the generated files on a separate branch --- public/fd_printf.html | 48 ------------------------------------------------ 1 file changed, 48 deletions(-) delete mode 100644 public/fd_printf.html (limited to 'public/fd_printf.html') diff --git a/public/fd_printf.html b/public/fd_printf.html deleted file mode 100644 index ff35631..0000000 --- a/public/fd_printf.html +++ /dev/null @@ -1,48 +0,0 @@ - - - - - `dprintf`: print formatted text directly to a file descriptor — Luke Shumaker - - - - -
Luke Shumaker » blog » fd_printf
-
-

dprintf: print formatted text directly to a file descriptor

-

This already existed as dprintf(3). I now feel stupid for having Implemented fd_printf.

-

The original post is as follows:

-
-

I wrote this while debugging some code, and thought it might be useful to others:

-
#define _GNU_SOURCE     /* vasprintf() */
-#include <stdarg.h>     /* va_start()/va_end() */
-#include <stdio.h>      /* vasprintf() */
-#include <stdlib.h>     /* free() */
-#include <unistd.h>     /* write() */
-
-int
-fd_printf(int fd, const char *format, ...)
-{
-    va_list arg;
-    int len;
-    char *str;
-
-    va_start(arg, format);
-    len = vasprintf(&str, format, arg);
-    va_end(arg);
-
-    write(fd, str, len);
-
-    free(str);
-    return len;
-}
-

It is a version of printf that prints to a file descriptor—where fprintf prints to a FILE* data structure.

-

The appeal of this is that FILE* I/O is buffered—which means mixing it with raw file descriptor I/O is going to produce weird results.

- -
- - - -- cgit v1.2.3