// <cstdlib> — C++ shim over the W65816 runtime's <stdlib.h>.
//
// Pulls in the existing extern-C-wrapped <stdlib.h> and re-exports the
// libc surface inside namespace std::.  EXIT_SUCCESS / EXIT_FAILURE /
// RAND_MAX / NULL stay as macros (per the C standard) and remain
// visible at global scope.

#ifndef _W65816_CXX_CSTDLIB
#define _W65816_CXX_CSTDLIB

#include <stdlib.h>

namespace std {

using ::size_t;
using ::div_t;
using ::ldiv_t;
using ::lldiv_t;

// ---- Memory allocation ----------------------------------------------
using ::malloc;
using ::calloc;
using ::realloc;
using ::free;
using ::aligned_alloc;
using ::aligned_free;
using ::posix_memalign;

// ---- Integer arithmetic ---------------------------------------------
using ::abs;
using ::labs;
using ::llabs;
using ::div;
using ::ldiv;
using ::lldiv;

// ---- String conversion ----------------------------------------------
using ::atoi;
using ::atol;
using ::atoll;
using ::atof;
using ::strtol;
using ::strtoul;
using ::strtoll;
using ::strtoull;
using ::strtod;
using ::strtof;

// ---- Sort / search --------------------------------------------------
using ::qsort;
using ::bsearch;

// ---- Program termination --------------------------------------------
using ::exit;
using ::_Exit;
using ::abort;
using ::quick_exit;
using ::atexit;
using ::at_quick_exit;

// ---- Environment ----------------------------------------------------
using ::getenv;
using ::system;

// ---- Pseudo-random --------------------------------------------------
using ::rand;
using ::srand;

}  // namespace std

#endif  // _W65816_CXX_CSTDLIB
