www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2014/01/10/17:27:05

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
X-Recipient: djgpp-workers AT delorie DOT com
Message-ID: <52D06613.80902@gmx.de>
Date: Fri, 10 Jan 2014 22:28:51 +0100
From: Juan Manuel Guerrero <juan DOT guerrero AT gmx DOT de>
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
MIME-Version: 1.0
To: djgpp-workers AT delorie DOT com
Subject: Re: Implementation of dprintf and vdprintf.
References: <52BDF357 DOT 9030702 AT gmx DOT de>
In-Reply-To: <52BDF357.9030702@gmx.de>
X-Provags-ID: V03:K0:ws3n6hnV9/lCXE9y07gJ69eHWf0VLyQESNz11adFd/68+i6tN4U
xUy7jFimH3L7Cpb1j/uKAqdrOG4c/jYyKOEBNDYtbKKlFhoHZow2jY3bNs4YxzFSbugleqZ
qqWDxLHH74HH3IxclLbgAxVMZqoyv/Ws/GqH6vl6bUqjoVUtySmHQ5E6v13b1mWO2UrO6rL
Dk0J8gsk4sw8LjOqshLEQ==
Reply-To: djgpp-workers AT delorie DOT com

Am 27.12.2013 22:38, schrieb Juan Manuel Guerrero:
> The patch below provides an implementation of dprintf and vdprintf together
> with a small test program.  AFAIK both are POSIX.1-2008.
> As usual, suggestions, objections, comments are welcome.
[snip]

OFYI, I have committed the patch below that implements dprintf and vdprintf
together with a check.

Regards,
Juan M. Guerrero



2013-12-23  Juan Manuel Guerrero  <juan DOT guerrero AT gmx DOT de>


     * djgpp/include/stdio.h:  Prototypes for dprintf and vdprintf added.

     * djgpp/src/libc/posix/stdio/dprintf.c:  Implementation of dprintf.

     * djgpp/src/libc/posix/stdio/dprintf.txh:  Documentation of dprintf.

     * djgpp/src/libc/posix/stdio/vdprintf.c:  Implementation of vdprintf.

     * djgpp/src/libc/posix/stdio/vdprintf.txh:  Documentation of vdprintf.

     * djgpp/src/libc/posix/stdio/makefile:  dprintf and vdprintf added to target list.

     * djgpp/src/docs/kb/wc204.txi:  Info about dprintf and vdprintf added.

     * djgpp/tests/libc/posix/stdio/dprintf.c: Check for dprintf.

     * djgpp/tests/libc/posix/stdio/makefile:  Check for dprintf added to target list.





diff -aprNU5 djgpp.orig/include/stdio.h djgpp/include/stdio.h
--- djgpp.orig/include/stdio.h    2012-09-23 09:49:12 +0100
+++ djgpp/include/stdio.h    2014-01-09 22:37:14 +0100
@@ -1,5 +1,7 @@
+/* Copyright (C) 2014 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
@@ -136,16 +138,18 @@ int    vsscanf(const char *_s, const char *

  #define L_ctermid 20
  #define L_cusrid
  /* #define STREAM_MAX    20 - DOS can change this */

+int    dprintf(int _fd, const char *_format, ...);
  int    fileno(FILE *_stream);
  FILE *    fdopen(int _fildes, const char *_type);
  int    mkstemp(char *_template);
  int    pclose(FILE *_pf);
  FILE *    popen(const char *_command, const char *_mode);
  char *    tempnam(const char *_dir, const char *_prefix);
+int    vdprintf(int _fd, const char *_format, va_list _ap);

  #ifndef _POSIX_SOURCE

  extern FILE __dj_stdprn, __dj_stdaux;
  #define stdprn    (&__dj_stdprn)
diff -aprNU5 djgpp.orig/src/docs/kb/wc204.txi djgpp/src/docs/kb/wc204.txi
--- djgpp.orig/src/docs/kb/wc204.txi    2014-01-09 22:21:30 +0100
+++ djgpp/src/docs/kb/wc204.txi    2014-01-09 22:36:14 +0100
@@ -1375,5 +1375,11 @@ The behavior of @code{mktemp} and @code{
  is available or not.  If @acronym{LFN} support is available the generated file names
  will comply with the @acronym{POSIX} standard.  This means all characters of the template
  before the trailing six upper case @code{X}s will not be truncated to create a valid
  short file name.  If @acronym{LFN} support is not available @code{mktemp} will behave
  as before.  This means only two characters before the trailing @code{X}s will be possible.
+
+@cindex @acronym{SUS} compliance, @code{stdio.h}
+@findex dprintf AT r{ added to the library}
+@findex vdprintf AT r{ added to the library}
+The functions @code{dprintf} and @code{vdprintf} were added to comply with
+the @acronym{POSIX} 1003.1-2008 standard.
diff -aprNU5 djgpp.orig/src/libc/posix/stdio/dprintf.c djgpp/src/libc/posix/stdio/dprintf.c
--- djgpp.orig/src/libc/posix/stdio/dprintf.c    1970-01-01 01:00:00 +0100
+++ djgpp/src/libc/posix/stdio/dprintf.c    2014-01-09 22:38:24 +0100
@@ -0,0 +1,18 @@
+/* Copyright (C) 2014 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+#include <stdio.h>
+#include <stdarg.h>
+
+int
+dprintf(int fd, const char *fmt, ...)
+{
+  va_list arg_list;
+  int written;
+
+
+  va_start(arg_list, fmt);
+  written = vdprintf(fd, fmt, arg_list);
+  va_end(arg_list);
+
+  return written;
+}
diff -aprNU5 djgpp.orig/src/libc/posix/stdio/dprintf.txh djgpp/src/libc/posix/stdio/dprintf.txh
--- djgpp.orig/src/libc/posix/stdio/dprintf.txh    1970-01-01 01:00:00 +0100
+++ djgpp/src/libc/posix/stdio/dprintf.txh    2014-01-09 22:36:14 +0100
@@ -0,0 +1,25 @@
+@node dprintf, stdio
+@findex dprintf
+@subheading Syntax
+
+@example
+#include <stdio.h>
+
+int dprintf(int file_desc, const char *format, ...);
+@end example
+
+@subheading Description
+
+The function @code{dprintf} is an exact analog of @code{fprintf} (@pxref{fprintf}),
+except that it output to a file descriptor @var{file_desc}
+instead of to a stdio stream.
+
+@subheading Return Value
+
+The number of characters written is returned; otherwise EOF
+is returned to flag encoding or buffer space errors.
+
+
+@subheading Portability
+
+@portability !ansi, posix
diff -aprNU5 djgpp.orig/src/libc/posix/stdio/makefile djgpp/src/libc/posix/stdio/makefile
--- djgpp.orig/src/libc/posix/stdio/makefile    1995-03-24 13:30:16 +0100
+++ djgpp/src/libc/posix/stdio/makefile    2014-01-09 22:38:24 +0100
@@ -1,8 +1,12 @@
+# Copyright (C) 2014 DJ Delorie, see COPYING.DJ for details
+# Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details
  # Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details
  TOP=../..

+SRC += dprintf.c
  SRC += fdopen.c
  SRC += fileno.c
  SRC += popen.c
+SRC += vdprintf.c

  include $(TOP)/../makefile.inc
diff -aprNU5 djgpp.orig/src/libc/posix/stdio/vdprintf.c djgpp/src/libc/posix/stdio/vdprintf.c
--- djgpp.orig/src/libc/posix/stdio/vdprintf.c    1970-01-01 01:00:00 +0100
+++ djgpp/src/libc/posix/stdio/vdprintf.c    2014-01-09 22:38:22 +0100
@@ -0,0 +1,22 @@
+/* Copyright (C) 2014 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int
+vdprintf(int fd, const char *fmt, va_list ap)
+{
+  char *string;
+  int written;
+
+
+  written = vasprintf(&string, fmt, ap);
+  if (string)
+  {
+    written = write(fd, string, written);
+    free(string);
+  }
+
+  return written;
+}
diff -aprNU5 djgpp.orig/src/libc/posix/stdio/vdprintf.txh djgpp/src/libc/posix/stdio/vdprintf.txh
--- djgpp.orig/src/libc/posix/stdio/vdprintf.txh    1970-01-01 01:00:00 +0100
+++ djgpp/src/libc/posix/stdio/vdprintf.txh    2014-01-09 22:36:14 +0100
@@ -0,0 +1,25 @@
+@node vdprintf, stdio
+@findex vdprintf
+@subheading Syntax
+
+@example
+#include <stdio.h>
+
+int vdprintf(int file_desc, const char *format, va_list arguments);
+@end example
+
+@subheading Description
+
+The function @code{vdprintf} is an exact analog of @code{vfprintf} (@pxref{vfprintf}),
+except that it output to a file descriptor @var{file_desc}
+instead of to a stdio stream.
+
+@subheading Return Value
+
+The number of characters written is returned; otherwise EOF
+is returned to flag encoding or buffer space errors.
+
+
+@subheading Portability
+
+@portability !ansi, posix
diff -aprNU5 djgpp.orig/tests/libc/posix/stdio/dprintf.c djgpp/tests/libc/posix/stdio/dprintf.c
--- djgpp.orig/tests/libc/posix/stdio/dprintf.c    1970-01-01 01:00:00 +0100
+++ djgpp/tests/libc/posix/stdio/dprintf.c    2014-01-09 22:36:14 +0100
@@ -0,0 +1,53 @@
+#include <stdio.h>
+
+int
+main(void)
+{
+  FILE *f;
+  char text_written[] = "A_test_text.";
+  int failure = 0;
+
+
+  f = fopen("file.txt", "w");
+  if (f)
+  {
+    int fd = fileno(f);
+    int written = dprintf(fd, "%s", text_written);
+
+    if (written + 1== sizeof text_written)
+    {
+      fclose(f);
+      f = fopen("file.txt", "r");
+
+      if (f)
+      {
+        char text_read[sizeof text_written + 1];
+        int read = fscanf(f, "%s", text_read);
+
+        if (read)
+        {
+          unsigned int i;
+
+          for (i = 0; i < sizeof text_written; i++)
+            if (text_written[i] != text_read[i])
+            {
+              failure++;
+              break;
+            }
+        }
+        else
+          failure++;
+      }
+      else
+        failure++;
+    }
+    else
+      failure++;
+  }
+  else
+    failure++;
+
+  printf("dprintf check %s\n", failure ? "failed." : "was successful.");
+
+  return failure;
+}
diff -aprNU5 djgpp.orig/tests/libc/posix/stdio/makefile djgpp/tests/libc/posix/stdio/makefile
--- djgpp.orig/tests/libc/posix/stdio/makefile    1970-01-01 01:00:00 +0100
+++ djgpp/tests/libc/posix/stdio/makefile    2014-01-09 22:36:14 +0100
@@ -0,0 +1,5 @@
+TOP=../..
+
+SRC += dprintf.c
+
+include $(TOP)/../makefile.inc

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019