From 392eb518d5e6dc5e0e7bb5c24a399c453c5a7b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 6 Feb 2008 17:11:02 +0000 Subject: [PATCH] * Added gcvt() implementation - this fixes bug #1757. * Added gcvt(), ecvt(), and fcvt() prototypes to stdlib.h - they are all marked legacy, but are still part of the POSIX standard, so we might want to implement them if the need arises. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23896 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/posix/stdlib.h | 22 ++++++++++++++++------ src/system/libroot/posix/stdlib/Jamfile | 1 + src/system/libroot/posix/stdlib/gcvt.c | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 src/system/libroot/posix/stdlib/gcvt.c diff --git a/headers/posix/stdlib.h b/headers/posix/stdlib.h index 7db19888ea..74962b5fc1 100644 --- a/headers/posix/stdlib.h +++ b/headers/posix/stdlib.h @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007, Haiku Inc. All Rights Reserved. + * Copyright 2002-2008, Haiku Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ #ifndef _STDLIB_H_ @@ -66,6 +66,11 @@ extern int system(const char *command); extern char *mktemp(char *name); extern int mkstemp(char *templat); +extern char *ecvt(double value, int digits, int *_decimalPoint, int *_sign); +extern char *fcvt(double value, int precision, int *_decimalPoint, + int *_sign); +extern char *gcvt(double value, int digits, char *buffer); + /* environment variables */ extern char **environ; extern char *getenv(const char *name); @@ -131,11 +136,16 @@ typedef int (*_compare_function)(const void *, const void *); extern void *bsearch(const void *key, const void *base, size_t numElements, size_t sizeOfElement, _compare_function); -extern int heapsort(void *base, size_t numElements, size_t sizeOfElement, _compare_function); -extern int mergesort(void *base, size_t numElements, size_t sizeOfElement, _compare_function); -extern void qsort(void *base, size_t numElements, size_t sizeOfElement, _compare_function); -extern int radixsort(u_char const **base, int numElements, u_char const *table, u_int endByte); -extern int sradixsort(u_char const **base, int numElements, u_char const *table, u_int endByte); +extern int heapsort(void *base, size_t numElements, size_t sizeOfElement, + _compare_function); +extern int mergesort(void *base, size_t numElements, size_t sizeOfElement, + _compare_function); +extern void qsort(void *base, size_t numElements, size_t sizeOfElement, + _compare_function); +extern int radixsort(u_char const **base, int numElements, + u_char const *table, u_int endByte); +extern int sradixsort(u_char const **base, int numElements, + u_char const *table, u_int endByte); /* misc math functions */ extern int abs(int number); diff --git a/src/system/libroot/posix/stdlib/Jamfile b/src/system/libroot/posix/stdlib/Jamfile index 7ae28698c6..fc28ed3799 100644 --- a/src/system/libroot/posix/stdlib/Jamfile +++ b/src/system/libroot/posix/stdlib/Jamfile @@ -12,6 +12,7 @@ MergeObject posix_stdlib.o : div.c env.c exit.c + gcvt.c heapsort.c merge.c mktemp.c diff --git a/src/system/libroot/posix/stdlib/gcvt.c b/src/system/libroot/posix/stdlib/gcvt.c new file mode 100644 index 0000000000..eec02e81fc --- /dev/null +++ b/src/system/libroot/posix/stdlib/gcvt.c @@ -0,0 +1,18 @@ +/* + * Copyright 2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + +#include + + +char * +gcvt(double value, int digits, char *buffer) +{ + sprintf(buffer, "%.*g", digits, value); + return buffer; +} + + +// TODO: eventually add ecvt(), and fcvt() as well, if needed.