#ifndef STRCMP # define STRCMP strcmp #endif /* Compare S1 and S2, returning less than, equal to or greater than zero if S1 is lexicographically less than, equal to or greater than S2. */ intSTRCMP(constchar *p1, constchar *p2) { constunsignedchar *s1 = (constunsignedchar *) p1; constunsignedchar *s2 = (constunsignedchar *) p2; unsignedchar c1, c2;
do { c1 = (unsignedchar) *s1++; c2 = (unsignedchar) *s2++; if (c1 == '\0') return c1 - c2; } while (c1 == c2);
/* Return the value of the environment variable NAME. This implementation is tuned a bit in that it assumes no environment variable has an empty name which of course should always be true. We have a special case for one character names so that for the general case we can assume at least two characters which we can access. By doing this we can avoid using the `strncmp' most of the time. */ char * getenv(constchar *name) { size_t len = strlen (name); char **ep; uint16_t name_start;
if (__environ == NULL || name[0] == '\0') returnNULL;
if (name[1] == '\0') { /* The name of the variable consists of only one character. Therefore the first two characters of the environment entry are this character and a '=' character. */ #if __BYTE_ORDER == __LITTLE_ENDIAN || !_STRING_ARCH_unaligned name_start = ('=' << 8) | *(constunsignedchar *) name; #else name_start = '=' | ((*(constunsignedchar *) name) << 8); #endif for (ep = __environ; *ep != NULL; ++ep) { #if _STRING_ARCH_unaligned uint16_t ep_start = *(uint16_t *) *ep; #else uint16_t ep_start = (((unsignedchar *) *ep)[0] | (((unsignedchar *) *ep)[1] << 8)); #endif if (name_start == ep_start) return &(*ep)[2]; } } else { #if _STRING_ARCH_unaligned name_start = *(constuint16_t *) name; #else name_start = (((constunsignedchar *) name)[0] | (((constunsignedchar *) name)[1] << 8)); #endif len -= 2; name += 2;