Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,10 @@ libshadow_la_SOURCES = \
alloc/realloc.h \
alloc/reallocf.c \
alloc/reallocf.h \
atoi/a2i/a2i.c \
atoi/a2i/a2i.h \
atoi/a2i/a2s.c \
atoi/a2i/a2s.h \
atoi/a2i/a2s_c.c \
atoi/a2i/a2s_c.h \
atoi/a2i/a2s_nc.c \
atoi/a2i/a2s_nc.h \
atoi/a2i/a2u.c \
atoi/a2i/a2u.h \
atoi/a2i/a2u_c.c \
atoi/a2i/a2u_c.h \
atoi/a2i/a2u_nc.c \
atoi/a2i/a2u_nc.h \
atoi/a2i.c \
atoi/a2i.h \
atoi/getnum.c \
atoi/getnum.h \
atoi/str2i.c \
atoi/str2i.h \
atoi/strtoi/strtoi.c \
atoi/strtoi/strtoi.h \
atoi/strtoi/strtou.c \
Expand Down
3 changes: 1 addition & 2 deletions lib/atoi/str2i.c → lib/atoi/a2i.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
// SPDX-FileCopyrightText: 2023-2025, Alejandro Colomar <[email protected]>
// SPDX-License-Identifier: BSD-3-Clause


#include "config.h"

#include "atoi/str2i.h"
#include "atoi/a2i.h"
78 changes: 78 additions & 0 deletions lib/atoi/a2i.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// SPDX-FileCopyrightText: 2023-2025, Alejandro Colomar <[email protected]>
// SPDX-License-Identifier: BSD-3-Clause


#ifndef SHADOW_INCLUDE_LIB_ATOI_A2I_H_
#define SHADOW_INCLUDE_LIB_ATOI_A2I_H_


#include "config.h"

#include <errno.h>
#include <stddef.h>

#include "atoi/strtoi/strtoi.h"
#include "atoi/strtoi/strtou_noneg.h"
#include "cast.h"
#include "typetraits.h"


/*
* See the manual of these macros in liba2i's documentation:
* <http://www.alejandro-colomar.es/share/dist/liba2i/git/HEAD/liba2i-HEAD.pdf>
*/


#define a2i_(T, QChar, n, s, endp, base, min, max) \
({ \
T *n_ = n; \
QChar **endp_ = endp; \
T min_ = min; \
T max_ = max; \
\
int status; \
\
*n_ = _Generic((T) 0, \
short: strtoi_, \
int: strtoi_, \
long: strtoi_, \
long long: strtoi_, \
unsigned short: strtou_noneg, \
unsigned int: strtou_noneg, \
unsigned long: strtou_noneg, \
unsigned long long: strtou_noneg \
)(s, const_cast(char **, endp_), base, min_, max_, &status); \
\
if (status != 0) \
errno = status; \
-!!status; \
})


// a2i - alpha to integer
#define a2i(T, n, s, ...) a2i_(T, QChar_of(s), n, s, __VA_ARGS__)

#define a2sh(...) a2i(short, __VA_ARGS__)
#define a2si(...) a2i(int, __VA_ARGS__)
#define a2sl(...) a2i(long, __VA_ARGS__)
#define a2sll(...) a2i(long long, __VA_ARGS__)

#define a2uh(...) a2i(unsigned short, __VA_ARGS__)
#define a2ui(...) a2i(unsigned int, __VA_ARGS__)
#define a2ul(...) a2i(unsigned long, __VA_ARGS__)
#define a2ull(...) a2i(unsigned long long, __VA_ARGS__)

#define str2i(T, ...) a2i(T, __VA_ARGS__, NULL, 0, type_min(T), type_max(T))

#define str2sh(...) str2i(short, __VA_ARGS__)
#define str2si(...) str2i(int, __VA_ARGS__)
#define str2sl(...) str2i(long, __VA_ARGS__)
#define str2sll(...) str2i(long long, __VA_ARGS__)

#define str2uh(...) str2i(unsigned short, __VA_ARGS__)
#define str2ui(...) str2i(unsigned int, __VA_ARGS__)
#define str2ul(...) str2i(unsigned long, __VA_ARGS__)
#define str2ull(...) str2i(unsigned long long, __VA_ARGS__)


#endif // include guard
7 changes: 0 additions & 7 deletions lib/atoi/a2i/a2i.c

This file was deleted.

62 changes: 0 additions & 62 deletions lib/atoi/a2i/a2i.h

This file was deleted.

7 changes: 0 additions & 7 deletions lib/atoi/a2i/a2s.c

This file was deleted.

20 changes: 0 additions & 20 deletions lib/atoi/a2i/a2s.h

This file was deleted.

17 changes: 0 additions & 17 deletions lib/atoi/a2i/a2s_c.c

This file was deleted.

64 changes: 0 additions & 64 deletions lib/atoi/a2i/a2s_c.h

This file was deleted.

17 changes: 0 additions & 17 deletions lib/atoi/a2i/a2s_nc.c

This file was deleted.

Loading
Loading