File: cstdlib

package info (click to toggle)
cppreference-doc 20170409-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 259,872 kB
  • sloc: xml: 570,184; python: 1,923; php: 520; makefile: 168; sh: 25; cpp: 9; ansic: 9
file content (126 lines) | stat: -rw-r--r-- 3,471 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*  Copyright (C) 2015  Povilas Kanapickas <povilas@radix.lt>

    This file is part of cppreference-doc

    This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
    Unported License. To view a copy of this license, visit
    http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative
    Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

    Permission is granted to copy, distribute and/or modify this document
    under the terms of the GNU Free Documentation License, Version 1.3 or
    any later version published by the Free Software Foundation; with no
    Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
*/

#ifndef CPPREFERENCE_CSTDLIB_H
#define CPPREFERENCE_CSTDLIB_H

namespace std {

// math utils
int abs(int n);
long      abs(long n);
#if CPPREFERENCE_STDVER>= 2011
long long abs(long long n);
#endif
long       labs(long n);
#if CPPREFERENCE_STDVER>= 2011
long long llabs(long long n);
#endif

struct div_t {
    int quot;
    int rem;
};

struct ldiv_t {
    long quot;
    long rem;
};

#if CPPREFERENCE_STDVER>= 2011
struct lldiv_t {
    long long quot;
    long long rem;
};
#endif

std::div_t     div(int x, int y);
std::ldiv_t    div(long x, long y);
#if CPPREFERENCE_STDVER>= 2011
std::lldiv_t   div(long long x, long long y);
#endif
std::ldiv_t   ldiv(long x, long y);
#if CPPREFERENCE_STDVER>= 2011
std::lldiv_t lldiv(long long x, long long y);
#endif

// string conversions

double atof(const char* nptr);
int atoi(const char* nptr);
long atol(const char* nptr);

#if CPPREFERENCE_STDVER>= 2011
long long atoll(const char* nptr);
#endif

double strtod(const char* nptr, char** endptr);
#if CPPREFERENCE_STDVER>= 2011
float strtof(const char* nptr, char** endptr);
long double strtold(const char* nptr, char** endptr);
#endif
long strtol(const char* nptr, char** endptr, int base);
#if CPPREFERENCE_STDVER>= 2011
long long strtoll(const char* nptr, char** endptr, int base);
#endif
unsigned long strtoul(const char* nptr, char** endptr, int base);
unsigned long long strtoull(const char* nptr, char** endptr, int base);

// multibyte string operations
#define MB_CUR_MAX 0 // actually unspecified
int mblen(const char* s, std::size_t n);
int mbtowc(wchar_t* pwc, const char* s, std::size_t n);
int wctomb(char* s, wchar_t wc);
std::size_t mbstowcs(wchar_t* dst, const char* src, std::size_t len);
std::size_t wcstombs(char* dst, const wchar_t* src, std::size_t len);

// random numbers
#define RAND_MAX 0 // actually unspecified
int rand();
void srand(unsigned seed);

// sorting
void qsort(void* ptr, std::size_t count, std::size_t size,
           int (*comp)(const void*, const void*));

void* bsearch(const void* key, const void* ptr, std::size_t count,
              std::size_t size, int (*comp)(const void*, const void*));

// program support utils
void abort();
void exit(int exit_code);
int atexit(void (*func)());

#define EXIT_SUCCESS 0 // actually impl-defined
#define EXIT_FAILURE 0 // actually impl-defined

#if CPPREFERENCE_STDVER>= 2011
void _Exit(int exit_code);
void quick_exit(int exit_code);
int at_quick_exit(void (*func)());
#endif

int system(const char* command);
char* getenv(const char* env_var);

// dynamic memory management
void* malloc(std::size_t size);
void* calloc(std::size_t num, std::size_t size);
void* realloc(void* ptr, std::size_t new_size);
void free(void* ptr);

} // namespace std

#endif // CPPREFERENCE_CSTDLIB_H