From 5848acdc90d34e903f097a94595cb6bda58b2bf0 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Mon, 27 Dec 2004 16:43:49 +0000 Subject: [PATCH] - Implement _onexit. - Port __dllonexit from Wine. - Fix vsscanf stream initialization. svn path=/trunk/; revision=12364 --- reactos/lib/msvcrt/misc/initterm.c | 19 ----------- reactos/lib/msvcrt/stdio/vsprintf.c | 2 +- reactos/lib/msvcrt/stdio/vsscanf.c | 2 +- reactos/lib/msvcrt/stdlib/atexit.c | 50 +++++++++++++++++++++++++---- 4 files changed, 46 insertions(+), 27 deletions(-) diff --git a/reactos/lib/msvcrt/misc/initterm.c b/reactos/lib/msvcrt/misc/initterm.c index 335729cc802..26f66a1c924 100644 --- a/reactos/lib/msvcrt/misc/initterm.c +++ b/reactos/lib/msvcrt/misc/initterm.c @@ -18,22 +18,3 @@ void _initterm(void (*fStart[])(void), void (*fEnd[])(void)) i++; } } - - -typedef int (* _onexit_t)(void); - -/* - * @unimplemented - */ -_onexit_t __dllonexit(_onexit_t func, void (** fStart[])(void), void (** fEnd[])(void)) -{ - return 0; -} - -/* - * @unimplemented - */ -_onexit_t _onexit(_onexit_t x) -{ - return x; -} diff --git a/reactos/lib/msvcrt/stdio/vsprintf.c b/reactos/lib/msvcrt/stdio/vsprintf.c index fad45e11023..9209bb1b3f3 100644 --- a/reactos/lib/msvcrt/stdio/vsprintf.c +++ b/reactos/lib/msvcrt/stdio/vsprintf.c @@ -13,7 +13,7 @@ vsprintf(char *str, const char *fmt, va_list ap) FILE f; int len; - f._flag = _IOWRT|_IOSTRG|_IOBINARY;; + f._flag = _IOWRT|_IOSTRG|_IOBINARY; f._ptr = str; f._cnt = INT_MAX; f._file = -1; diff --git a/reactos/lib/msvcrt/stdio/vsscanf.c b/reactos/lib/msvcrt/stdio/vsscanf.c index 42348a1a111..b24fe72f620 100644 --- a/reactos/lib/msvcrt/stdio/vsscanf.c +++ b/reactos/lib/msvcrt/stdio/vsscanf.c @@ -39,7 +39,7 @@ int __vsscanf(const char *s,const char *format,va_list arg) memset((void *) &f, 0, sizeof (f)); - f._flag = _IOREAD; + f._flag = _IOREAD|_IOSTRG|_IOBINARY; f._ptr = (char *)s; f._base = (char *)s; f._bufsiz = strlen(s); diff --git a/reactos/lib/msvcrt/stdlib/atexit.c b/reactos/lib/msvcrt/stdlib/atexit.c index 66a084d8870..6d08dfd160f 100644 --- a/reactos/lib/msvcrt/stdlib/atexit.c +++ b/reactos/lib/msvcrt/stdlib/atexit.c @@ -2,20 +2,58 @@ #include #include +typedef int (* _onexit_t)(void); + +/* + * @implemented + * + * Ported from WINE + * Copyright (C) 2000 Jon Griffiths + */ +_onexit_t __dllonexit(_onexit_t func, _onexit_t **start, _onexit_t **end) +{ + _onexit_t *tmp; + int len; + + if (!start || !*start || !end || !*end) + return NULL; + + len = (*end - *start); + if (++len <= 0) + return NULL; + + tmp = (_onexit_t *)realloc(*start, len * sizeof(tmp)); + if (!tmp) + return NULL; + + *start = tmp; + *end = tmp + len; + tmp[len - 1] = func; + + return func; +} + /* * @implemented */ -int -atexit(void (*a)(void)) +_onexit_t _onexit(_onexit_t a) { struct __atexit *ap; if (a == 0) - return -1; + return NULL; ap = (struct __atexit *)malloc(sizeof(struct __atexit)); if (!ap) - return -1; + return NULL; ap->__next = __atexit_ptr; - ap->__function = a; + ap->__function = (void (*)(void))a; __atexit_ptr = ap; - return 0; + return a; +} + +/* + * @implemented + */ +int atexit(void (*a)(void)) +{ + return _onexit((_onexit_t)a) == (_onexit_t)a ? 0 : -1; }