vsnprintf()

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

vsnprintf()

Albert Chin-69
I take it vsnprintf() is required? From src/cutils.c:
  int
  octave_raw_vsnprintf (char *buf, size_t n, const char *fmt, va_list args)
  {
    return vsnprintf (buf, n, fmt, args);
  }

--
albert chin ([hidden email])


Reply | Threaded
Open this post in threaded view
|

Re: vsnprintf()

Albert Chin-69
On Wed, Mar 19, 2003 at 09:48:03PM -0600, Albert Chin wrote:
> I take it vsnprintf() is required? From src/cutils.c:
>   int
>   octave_raw_vsnprintf (char *buf, size_t n, const char *fmt, va_list args)
>   {
>     return vsnprintf (buf, n, fmt, args);
>   }

The patch below fixes this. This, in addition to importing all *trio*
files from the link below gets Octave to build and run on Tru64 UNIX
4.0.
  http://daniel.haxx.se/trio/
This might seem like overkill just to get vsnprintf but it's easy :)

The AC_FUNC_VSNPRINTF_C99 macro is stolen from Glib 2.2.1. The license
for Glib is the LGPL so this macro should fall under that license.

--
albert chin ([hidden email])

-- snip snip
Index: aclocal.m4
===================================================================
RCS file: /cvs/octave/aclocal.m4,v
retrieving revision 1.75
diff -u -3 -p -r1.75 aclocal.m4
--- aclocal.m4 2002/11/20 16:56:47 1.75
+++ aclocal.m4 2003/03/20 16:23:01
@@ -746,3 +746,49 @@ fi
 AC_SUBST([SED], $octave_cv_path_sed)
 AC_MSG_RESULT([$SED])
 ])
+
+dnl @synopsis AC_FUNC_VSNPRINTF_C99
+dnl
+dnl Check whether there is a vsnprintf() function with C99 semantics installed.
+dnl
+AC_DEFUN([AC_FUNC_VSNPRINTF_C99],
+[AC_CACHE_CHECK(for C99 vsnprintf,
+  ac_cv_func_vsnprintf_c99,
+[AC_TRY_RUN(
+[#include <stdio.h>
+#include <stdarg.h>
+
+int
+doit(char * s, ...)
+{
+  char buffer[32];
+  va_list args;
+  int r;
+
+  va_start(args, s);
+  r = vsnprintf(buffer, 5, s, args);
+  va_end(args);
+
+  if (r != 7)
+    exit(1);
+
+  exit(0);
+
+  return (0);
+}
+
+int
+main(void)
+{
+  doit("1234567");
+  exit(1);
+}], ac_cv_func_vsnprintf_c99=yes, ac_cv_func_vsnprintf_c99=no, ac_cv_func_vsnprintf_c99=no)])
+dnl Note that the default is to be pessimistic in the case of cross compilation.
+dnl If you know that the target has a C99 vsnprintf(), you can get around this
+dnl by setting ac_func_vsnprintf_c99 to yes, as described in the Autoconf manual.
+if test $ac_cv_func_vsnprintf_c99 = yes; then
+  AC_DEFINE(HAVE_C99_VSNPRINTF, 1,
+            [Define if you have a version of the vsnprintf function
+             with semantics as specified by the ISO C99 standard.])
+fi
+])# AC_FUNC_VSNPRINTF_C99
Index: configure.in
===================================================================
RCS file: /cvs/octave/configure.in,v
retrieving revision 1.413
diff -u -3 -p -r1.413 configure.in
--- configure.in 2003/02/20 16:46:37 1.413
+++ configure.in 2003/03/20 16:23:03
@@ -936,7 +959,11 @@ AC_CHECK_FUNCS(atexit bcopy bzero dup2 e
   rindex rmdir select setgrent setpwent setvbuf sigaction siglongjmp \
   sigpending sigprocmask sigsuspend stat strcasecmp strdup \
   strerror strftime stricmp strncasecmp strnicmp strptime symlink \
-  tempnam umask unlink usleep vfprintf vsprintf vsnprintf waitpid)
+  tempnam umask unlink usleep vfprintf vsprintf waitpid)
+AC_CHECK_FUNCS(vsnprintf, ,[
+  TRIO_SRC="trio.c trionan.c triostr.c"])
+AC_SUBST(TRIO_SRC)
+AC_FUNC_VSNPRINTF_C99
 
 OCTAVE_SMART_PUTENV
 
Index: src/Makefile.in
===================================================================
RCS file: /cvs/octave/src/Makefile.in,v
retrieving revision 1.314
diff -u -3 -p -r1.314 Makefile.in
--- src/Makefile.in 2003/02/20 08:35:55 1.314
+++ src/Makefile.in 2003/03/20 16:23:21
@@ -89,6 +89,8 @@ INCLUDES := Cell.h base-list.h c-file-pt
  siglist.h symtab.h sysdep.h token.h toplev.h unwind-prot.h utils.h \
  variables.h version.h xdiv.h xpow.h $(OV_INCLUDES) $(PT_INCLUDES)
 
+TRIO_SRC := @TRIO_SRC@
+
 TI_XSRC := Array-oc.cc Array-os.cc Array-sym.cc Array-tc.cc
 
 TI_SRC := $(addprefix TEMPLATE-INST/, $(TI_XSRC))
@@ -132,7 +134,8 @@ DIST_SRC := Cell.cc c-file-ptr-stream.cc
  syscalls.cc sysdep.cc system.c token.cc toplev.cc \
  unwind-prot.cc utils.cc variables.cc xdiv.cc xpow.cc \
  $(OV_SRC) \
- $(PT_SRC)
+ $(PT_SRC) \
+ $(TRIO_SRC)
 
 SOURCES := $(DIST_SRC) $(OP_SRC) $(TI_SRC)
 
Index: src/cutils.c
===================================================================
RCS file: /cvs/octave/src/cutils.c,v
retrieving revision 1.18
diff -u -3 -p -r1.18 cutils.c
--- src/cutils.c 2003/01/22 22:02:23 1.18
+++ src/cutils.c 2003/03/20 16:23:21
@@ -50,6 +50,11 @@ Software Foundation, 59 Temple Place - S
 #include <sys/poll.h>
 #endif
 
+#ifndef HAVE_VSNPRINTF
+#include "trio.h"
+#define vsnprintf trio_vsnprintf
+#endif
+
 #endif
 
 void
Index: src/utils.cc
===================================================================
RCS file: /cvs/octave/src/utils.cc,v
retrieving revision 1.158
diff -u -3 -p -r1.158 utils.cc
--- src/utils.cc 2003/01/22 22:02:23 1.158
+++ src/utils.cc 2003/03/20 16:23:24
@@ -884,12 +884,6 @@ octave_vformat (std::ostream& os, const
   return retval;
 }
 
-/* XXX FIXME XXX -- we really need a configure test for this.  */
-
-#if defined __GNUC__ && __GNUC__ >= 3
-#define HAVE_C99_VSNPRINTF 1
-#endif
-
 // We manage storage.  User should not free it, and its contents are
 // only valid until next call to vsnprintf.
 


Reply | Threaded
Open this post in threaded view
|

Re: vsnprintf()

Paul Kienzle
Albert Chin wrote:

>The patch below fixes this. This, in addition to importing all *trio*
>files from the link below gets Octave to build and run on Tru64 UNIX
>4.0.
>  http://daniel.haxx.se/trio/
>This might seem like overkill just to get vsnprintf but it's easy :)
>  
>
I put up my SGI notes on the octave
wiki --- please put any special instructions
for Tru64 Unix there (http://gnufans.net/octave.pl).
Though you might wait to see if John accepts your
patch first.

I'm hoping Deepak will provide a mechanism for
uploading tarballs to the wiki as well.  You might
want to ask him about it.

Paul Kienzle
[hidden email]