Browse Source

stdlib: add exit() based on target-provided _Exit()

This is implemented for gint only currently; on Vhex, _Exit() is likely
just going to be a syscall. For CASIOWIN, this is slightly more
difficult, as there is no native exit syscall.
master
Lephenixnoir 8 months ago
parent
commit
4b90740d3b
Signed by: Lephenixnoir GPG Key ID: 1BBA026E13FC0495
  1. 1
      CMakeLists.txt
  2. 7
      STATUS
  3. 9
      include/stdlib.h
  4. 8
      include/target/casiowin-cg/bits/exit.h
  5. 8
      include/target/casiowin-fx/bits/exit.h
  6. 8
      include/target/gint/bits/exit.h
  7. 7
      include/target/vhex-generic/bits/exit.h
  8. 10
      src/libc/stdlib/abort.c
  9. 11
      src/libc/stdlib/exit.c

1
CMakeLists.txt

@ -125,6 +125,7 @@ set(SOURCES
src/libc/stdlib/atoll.c
src/libc/stdlib/calloc.c
src/libc/stdlib/div.c
src/libc/stdlib/exit.c
src/libc/stdlib/labs.c
src/libc/stdlib/ldiv.c
src/libc/stdlib/llabs.c

7
STATUS

@ -102,7 +102,12 @@ DONE: Function/symbol/macro is defined, builds, links, and is tested
7.20.1.4 strtol, strtoul, strtoll, strtoull: DONE
! 7.20.2 Pseudo-random sequence generation functions: TODO
! 7.20.3 Memory management functions: TODO (check existing code first)
! 7.20.4 Communication with the environment: TODO
! 7.20.4.1 abort: BDEPS(raise)
! 7.20.4.2 atexit: TODO
7.20.4.3 exit: DONE (missing stream flushing/closing/etc)
7.20.4.4 _Exit: DONE (gint only)
! 7.20.4.5 getenv: TODO
! 7.20.4.6 system: TODO
! 7.20.5 Searching and sorting utilities: TODO
7.20.6.1 abs, labs, llabs: DONE
7.20.6.2 div, ldiv, lldiv: DONE

9
include/stdlib.h

@ -3,6 +3,7 @@
#include <stddef.h>
#include <stdint.h>
#include <bits/exit.h>
/* Dynamic memory management. */
@ -27,6 +28,14 @@ extern void *reallocarray(void *__ptr, size_t __nmemb, size_t __size);
/* Free a block allocated by `malloc', `realloc' or `calloc'. */
extern void free(void *__ptr);
/* Communication with the environment. */
/* Exit; calls handlers, flushes and closes streams and temporary files. */
void exit(int __status);
/* Exit immediately, bypassing exit handlers or signal handlers. */
void _Exit(int __status);
/* Integer arithmetic functions. */
extern int abs(int __j);

8
include/target/casiowin-cg/bits/exit.h

@ -0,0 +1,8 @@
#ifndef __BITS_EXIT_H__
# define __BITS_EXIT_H__
/* Exit codes for CASIOWIN add-ins. */
#define EXIT_SUCCESS 1
#define EXIT_FAILURE 0
#endif /*__BITS_EXIT_H__*/

8
include/target/casiowin-fx/bits/exit.h

@ -0,0 +1,8 @@
#ifndef __BITS_EXIT_H__
# define __BITS_EXIT_H__
/* Exit codes for CASIOWIN add-ins. */
#define EXIT_SUCCESS 1
#define EXIT_FAILURE 0
#endif /*__BITS_EXIT_H__*/

8
include/target/gint/bits/exit.h

@ -0,0 +1,8 @@
#ifndef __BITS_EXIT_H__
# define __BITS_EXIT_H__
/* Exit codes for CASIOWIN add-ins. */
#define EXIT_SUCCESS 1
#define EXIT_FAILURE 0
#endif /*__BITS_EXIT_H__*/

7
include/target/vhex-generic/bits/exit.h

@ -0,0 +1,7 @@
#ifndef __BITS_EXIT_H__
# define __BITS_EXIT_H__
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
#endif /*__BITS_EXIT_H__*/

10
src/libc/stdlib/abort.c

@ -0,0 +1,10 @@
#include <stdlib.h>
#include <bits/stdlib.h>
void abort(int rc)
{
/* TODO: Close BFile handles (essential) */
raise(SIGABRT);
_Exit(EXIT_FAILURE);
}

11
src/libc/stdlib/exit.c

@ -0,0 +1,11 @@
#include <stdlib.h>
void exit(int rc)
{
/* TODO: invoke atexit callbacks */
/* TODO: exit: Flush all streams */
/* TODO: exit: Close all streams */
/* TODO: exit: Remove temporary files */
_Exit(rc);
}
Loading…
Cancel
Save