about summary refs log tree commit diff
path: root/misc
diff options
context:
space:
mode:
Diffstat (limited to 'misc')
-rw-r--r--misc/Makefile2
-rw-r--r--misc/efgcvt.c23
-rw-r--r--misc/efgcvt_r.c38
-rw-r--r--misc/mntent.c11
-rw-r--r--misc/qefgcvt.c26
-rw-r--r--misc/qefgcvt_r.c26
6 files changed, 103 insertions, 23 deletions
diff --git a/misc/Makefile b/misc/Makefile
index 4ffad986ab..01e223836f 100644
--- a/misc/Makefile
+++ b/misc/Makefile
@@ -52,7 +52,7 @@ routines := brk sbrk sstk ioctl \
 	    insremque getttyent getusershell getpass ttyslot \
 	    syslog syscall daemon \
 	    mmap munmap mprotect msync madvise \
-	    efgcvt efgcvt_r \
+	    efgcvt efgcvt_r qefgcvt qefgcvt_r \
 	    hsearch hsearch_r tsearch lsearch \
 	    err error
 aux := init-misc
diff --git a/misc/efgcvt.c b/misc/efgcvt.c
index e8a05176e6..73be3e1c5c 100644
--- a/misc/efgcvt.c
+++ b/misc/efgcvt.c
@@ -21,11 +21,20 @@ Cambridge, MA 02139, USA.  */
 #include <stdlib.h>
 #include <float.h>
 
+#ifndef FLOAT_TYPE
+#define FLOAT_TYPE double
+#define FUNC_PREFIX
+#define FLOAT_FMT_FLAG
 #define MAXDIG (DBL_DIG + DBL_MAX_10_EXP)
+#endif
+
+#define APPEND(a, b) APPEND2 (a, b)
+#define APPEND2(a, b) a##b
+
 
 char *
-fcvt (value, ndigit, decpt, sign)
-     double value;
+APPEND (FUNC_PREFIX, fcvt) (value, ndigit, decpt, sign)
+     FLOAT_TYPE value;
      int ndigit, *decpt, *sign;
 {
   static char buf[MAXDIG];
@@ -36,8 +45,8 @@ fcvt (value, ndigit, decpt, sign)
 }
 
 char *
-ecvt (value, ndigit, decpt, sign)
-     double value;
+APPEND (FUNC_PREFIX, ecvt) (value, ndigit, decpt, sign)
+     FLOAT_TYPE value;
      int ndigit, *decpt, *sign;
 {
   static char buf[MAXDIG];
@@ -48,11 +57,11 @@ ecvt (value, ndigit, decpt, sign)
 }
 
 char *
-gcvt (value, ndigit, buf)
-     double value;
+APPEND (FUNC_PREFIX, gcvt) (value, ndigit, buf)
+     FLOAT_TYPE value;
      int ndigit;
      char *buf;
 {
-  sprintf (buf, "%.*g", ndigit, value);
+  sprintf (buf, "%.*" FLOAT_FMT_FLAG "g", ndigit, value);
   return buf;
 }
diff --git a/misc/efgcvt_r.c b/misc/efgcvt_r.c
index 6a65583a6a..cbd5c271ba 100644
--- a/misc/efgcvt_r.c
+++ b/misc/efgcvt_r.c
@@ -1,5 +1,5 @@
 /* [efg]cvt -- compatibility functions for floating point formatting,
-   reentrent versions.
+   reentrant versions.
 Copyright (C) 1995, 1996 Free Software Foundation, Inc.
 This file is part of the GNU C Library.
 
@@ -25,9 +25,24 @@ Boston, MA 02111-1307, USA.  */
 #include <math.h>
 #include <stdlib.h>
 
+#ifndef FLOAT_TYPE
+#define FLOAT_TYPE double
+#define FUNC_PREFIX
+#define FLOAT_FMT_FLAG
+#define FLOAT_NAME_EXT
+#endif
+
+#define APPEND(a, b) APPEND2 (a, b)
+#define APPEND2(a, b) a##b
+
+#define FLOOR APPEND(floor, FLOAT_NAME_EXT)
+#define FABS APPEND(fabs, FLOAT_NAME_EXT)
+#define LOG10 APPEND(log10, FLOAT_NAME_EXT)
+
+
 int
-fcvt_r (value, ndigit, decpt, sign, buf, len)
-     double value;
+APPEND (FUNC_PREFIX, fcvt_r) (value, ndigit, decpt, sign, buf, len)
+     FLOAT_TYPE value;
      int ndigit, *decpt, *sign;
      char *buf;
      size_t len;
@@ -44,7 +59,7 @@ fcvt_r (value, ndigit, decpt, sign, buf, len)
   if (*sign)
     value = - value;
 
-  n = snprintf (buf, len, "%.*f", ndigit, value);
+  n = snprintf (buf, len, "%.*" FLOAT_FMT_FLAG "f", ndigit, value);
   if (n < 0)
     return -1;
 
@@ -60,33 +75,34 @@ fcvt_r (value, ndigit, decpt, sign, buf, len)
   return 0;
 }
 
-weak_extern (floor) weak_extern (log10) weak_extern (fabs)
+#define weak_extern2(name) weak_extern (name)
+weak_extern2 (FLOOR) weak_extern2 (LOG10) weak_extern2 (FABS)
 
 int
-ecvt_r (value, ndigit, decpt, sign, buf, len)
-     double value;
+APPEND (FUNC_PREFIX, ecvt_r) (value, ndigit, decpt, sign, buf, len)
+     FLOAT_TYPE value;
      int ndigit, *decpt, *sign;
      char *buf;
      size_t len;
 {
-  double (*log10_function) (double) = &log10;
+  FLOAT_TYPE (*log10_function) (FLOAT_TYPE) = &LOG10;
 
   if (log10_function)
     {
       /* Use the reasonable code if -lm is included.  */
-      ndigit -= (int) floor (log10 (fabs (value)));
+      ndigit -= (int) FLOOR (LOG10 (FABS (value)));
       if (ndigit < 0)
 	ndigit = 0;
     }
   else
     {
       /* Slow code that doesn't require -lm functions.  */
-      double d;
+      FLOAT_TYPE d;
       for (d = value < 0.0 ? - value : value;
 	   ndigit > 0 && d >= 10.0;
 	   d *= 0.1)
 	--ndigit;
     }
 
-  return fcvt_r (value, ndigit, decpt, sign, buf, len);
+  return APPEND (FUNC_PREFIX, fcvt_r) (value, ndigit, decpt, sign, buf, len);
 }
diff --git a/misc/mntent.c b/misc/mntent.c
index 6cf74c2160..0aa1fb8cde 100644
--- a/misc/mntent.c
+++ b/misc/mntent.c
@@ -34,9 +34,9 @@ setmntent (const char *file, const char *mode)
 int
 endmntent (FILE *stream)
 {
-  if (fclose (stream) != 0) 
-      return 0;
-  return 1;
+  if (stream)		/* SunOS 4.x allows for NULL stream */
+    fclose (stream);
+  return 1;		/* SunOS 4.x says to always return 1 */
 }
 
 
@@ -92,6 +92,9 @@ getmntent (FILE *stream)
 int
 addmntent (FILE *stream, const struct mntent *mnt)
 {
+  if (fseek (stream, 0, SEEK_END))
+    return 1;
+
   return (fprintf (stream, "%s %s %s %s %d %d\n",
 		   mnt->mnt_fsname,
 		   mnt->mnt_dir,
@@ -99,7 +102,7 @@ addmntent (FILE *stream, const struct mntent *mnt)
 		   mnt->mnt_opts,
 		   mnt->mnt_freq,
 		   mnt->mnt_passno)
-	  < 0 ? -1 : 0);
+	  < 0 ? 1 : 0);
 }
 
 /* Search MNT->mnt_opts for an option matching OPT.
diff --git a/misc/qefgcvt.c b/misc/qefgcvt.c
new file mode 100644
index 0000000000..2015fb8d4f
--- /dev/null
+++ b/misc/qefgcvt.c
@@ -0,0 +1,26 @@
+/* q[efg]cvt -- compatibility functions for floating point formatting,
+		long double version.
+Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#define FLOAT_TYPE long double
+#define FUNC_PREFIX q
+#define FLOAT_FMT_FLAG "L"
+#define MAXDIG (LDBL_DIG + LDBL_MAX_10_EXP)
+
+#include "efgcvt.c"
diff --git a/misc/qefgcvt_r.c b/misc/qefgcvt_r.c
new file mode 100644
index 0000000000..67cf44880c
--- /dev/null
+++ b/misc/qefgcvt_r.c
@@ -0,0 +1,26 @@
+/* [efg]cvt -- compatibility functions for floating point formatting,
+   reentrant, long double versions.
+Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#define FLOAT_TYPE long double
+#define FUNC_PREFIX q
+#define FLOAT_FMT_FLAG "L"
+#define FLOAT_NAME_EXT l
+
+#include "efgcvt_r.c"