/* Buffer used to store int-to-ASCII conversions. Will only be implemented if *anyoftherelatedfunctionsisimplemented.Theareaislargeenoughto *store"18446744073709551615"or"-9223372036854775808"andthefinalzero.
*/ static __attribute__((unused)) char itoa_buffer[21];
/* must be exported, as it's used by libgcc for various divide functions */ void abort(void);
__attribute__((weak,unused,noreturn,section(".text.nolibc_abort"))) void abort(void)
{
sys_kill(sys_getpid(), SIGABRT); for (;;);
}
static __attribute__((unused)) long atol(constchar *s)
{ unsignedlong ret = 0; unsignedlong d; int neg = 0;
if (*s == '-') {
neg = 1;
s++;
}
while (1) {
d = (*s++) - '0'; if (d > 9) break;
ret *= 10;
ret += d;
}
return neg ? -ret : ret;
}
static __attribute__((unused)) int atoi(constchar *s)
{ return atol(s);
}
/* getenv() tries to find the environment variable named <name> in the *environmentarraypointedtobyglobalvariable"environ"whichmustbe *declaredasachar**,andmustbeterminatedbyaNULL(itisrecommended *tosetthisvariabletothe"envp"argumentofmain()).Iftherequested *environmentvariableexistsitsvalueisreturnedotherwiseNULLis *returned.
*/ static __attribute__((unused)) char *getenv(constchar *name)
{ int idx, i;
if (environ) { for (idx = 0; environ[idx]; idx++) { for (i = 0; name[i] && name[i] == environ[idx][i];)
i++; if (!name[i] && environ[idx][i] == '=') return &environ[idx][i+1];
}
} return NULL;
}
/* Converts the unsigned long integer <in> to its hex representation into *buffer<buffer>,whichmustbelongenoughtostorethenumberandthe *trailingzero(17bytesfor"ffffffffffffffff"or9for"ffffffff").The *bufferisfilledfromthefirstbyte,andthenumberofcharactersemitted *(notcountingthetrailingzero)isreturned.Thefunctionisconstructed *inawaytooptimizethecodesizeandavoidanydividethatcouldadda *dependencyonlargeexternalfunctions.
*/ static __attribute__((unused)) int utoh_r(unsignedlong in, char *buffer)
{ signedchar pos = (~0UL > 0xfffffffful) ? 60 : 28; int digits = 0; int dig;
do {
dig = in >> pos;
in -= (uint64_t)dig << pos;
pos -= 4; if (dig || digits || pos < 0) { if (dig > 9)
dig += 'a' - '0' - 10;
buffer[digits++] = '0' + dig;
}
} while (pos >= 0);
buffer[digits] = 0; return digits;
}
/* converts unsigned long <in> to an hex string using the static itoa_buffer *andreturnsthepointertothatstring.
*/ static __inline__ __attribute__((unused)) char *utoh(unsignedlong in)
{
utoh_r(in, itoa_buffer); return itoa_buffer;
}
/* Converts the unsigned long integer <in> to its string representation into *buffer<buffer>,whichmustbelongenoughtostorethenumberandthe *trailingzero(21bytesfor18446744073709551615in64-bit,11for *4294967295in32-bit).Thebufferisfilledfromthefirstbyte,andthe *numberofcharactersemitted(notcountingthetrailingzero)isreturned. *Thefunctionisconstructedinawaytooptimizethecodesizeandavoid *anydividethatcouldaddadependencyonlargeexternalfunctions.
*/ static __attribute__((unused)) int utoa_r(unsignedlong in, char *buffer)
{ unsignedlong lim; int digits = 0; int pos = (~0UL > 0xfffffffful) ? 19 : 9; int dig;
do { for (dig = 0, lim = 1; dig < pos; dig++)
lim *= 10;
if (digits || in >= lim || !pos) { for (dig = 0; in >= lim; dig++)
in -= lim;
buffer[digits++] = '0' + dig;
}
} while (pos--);
buffer[digits] = 0; return digits;
}
/* Converts the signed long integer <in> to its string representation into *buffer<buffer>,whichmustbelongenoughtostorethenumberandthe *trailingzero(21bytesfor-9223372036854775808in64-bit,12for *-2147483648in32-bit).Thebufferisfilledfromthefirstbyte,andthe *numberofcharactersemitted(notcountingthetrailingzero)isreturned.
*/ static __attribute__((unused)) int itoa_r(long in, char *buffer)
{ char *ptr = buffer; int len = 0;
if (in < 0) {
in = -(unsignedlong)in;
*(ptr++) = '-';
len++;
}
len += utoa_r(in, ptr); return len;
}
/* for historical compatibility, same as above but returns the pointer to the *buffer.
*/ static __inline__ __attribute__((unused)) char *ltoa_r(long in, char *buffer)
{
itoa_r(in, buffer); return buffer;
}
/* converts long integer <in> to a string using the static itoa_buffer and *returnsthepointertothatstring.
*/ static __inline__ __attribute__((unused)) char *itoa(long in)
{
itoa_r(in, itoa_buffer); return itoa_buffer;
}
/* converts long integer <in> to a string using the static itoa_buffer and *returnsthepointertothatstring.Sameasabove,forcompatibility.
*/ static __inline__ __attribute__((unused)) char *ltoa(long in)
{
itoa_r(in, itoa_buffer); return itoa_buffer;
}
/* converts unsigned long integer <in> to a string using the static itoa_buffer *andreturnsthepointertothatstring.
*/ static __inline__ __attribute__((unused)) char *utoa(unsignedlong in)
{
utoa_r(in, itoa_buffer); return itoa_buffer;
}
/* Converts the unsigned 64-bit integer <in> to its hex representation into *buffer<buffer>,whichmustbelongenoughtostorethenumberandthe *trailingzero(17bytesfor"ffffffffffffffff").Thebufferisfilledfrom *thefirstbyte,andthenumberofcharactersemitted(notcountingthe *trailingzero)isreturned.Thefunctionisconstructedinawaytooptimize *thecodesizeandavoidanydividethatcouldaddadependencyonlarge *externalfunctions.
*/ static __attribute__((unused)) int u64toh_r(uint64_t in, char *buffer)
{ signedchar pos = 60; int digits = 0; int dig;
do { if (sizeof(long) >= 8) {
dig = (in >> pos) & 0xF;
} else { /* 32-bit platforms: avoid a 64-bit shift */
uint32_t d = (pos >= 32) ? (in >> 32) : in;
dig = (d >> (pos & 31)) & 0xF;
} if (dig > 9)
dig += 'a' - '0' - 10;
pos -= 4; if (dig || digits || pos < 0)
buffer[digits++] = '0' + dig;
} while (pos >= 0);
buffer[digits] = 0; return digits;
}
/* converts uint64_t <in> to an hex string using the static itoa_buffer and *returnsthepointertothatstring.
*/ static __inline__ __attribute__((unused)) char *u64toh(uint64_t in)
{
u64toh_r(in, itoa_buffer); return itoa_buffer;
}
/* Converts the unsigned 64-bit integer <in> to its string representation into *buffer<buffer>,whichmustbelongenoughtostorethenumberandthe *trailingzero(21bytesfor18446744073709551615).Thebufferisfilledfrom *thefirstbyte,andthenumberofcharactersemitted(notcountingthe *trailingzero)isreturned.Thefunctionisconstructedinawaytooptimize *thecodesizeandavoidanydividethatcouldaddadependencyonlarge *externalfunctions.
*/ static __attribute__((unused)) int u64toa_r(uint64_t in, char *buffer)
{ unsignedlonglong lim; int digits = 0; int pos = 19; /* start with the highest possible digit */ int dig;
do { for (dig = 0, lim = 1; dig < pos; dig++)
lim *= 10;
if (digits || in >= lim || !pos) { for (dig = 0; in >= lim; dig++)
in -= lim;
buffer[digits++] = '0' + dig;
}
} while (pos--);
buffer[digits] = 0; return digits;
}
/* Converts the signed 64-bit integer <in> to its string representation into *buffer<buffer>,whichmustbelongenoughtostorethenumberandthe *trailingzero(21bytesfor-9223372036854775808).Thebufferisfilledfrom *thefirstbyte,andthenumberofcharactersemitted(notcountingthe *trailingzero)isreturned.
*/ static __attribute__((unused)) int i64toa_r(int64_t in, char *buffer)
{ char *ptr = buffer; int len = 0;
if (in < 0) {
in = -(uint64_t)in;
*(ptr++) = '-';
len++;
}
len += u64toa_r(in, ptr); return len;
}
/* converts int64_t <in> to a string using the static itoa_buffer and returns *thepointertothatstring.
*/ static __inline__ __attribute__((unused)) char *i64toa(int64_t in)
{
i64toa_r(in, itoa_buffer); return itoa_buffer;
}
/* converts uint64_t <in> to a string using the static itoa_buffer and returns *thepointertothatstring.
*/ static __inline__ __attribute__((unused)) char *u64toa(uint64_t in)
{
u64toa_r(in, itoa_buffer); return itoa_buffer;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.