SORRY. It seems I've screwed up my commit for http://breakpad.appspot.com/411002/, since revision 1001 only contains the new src/client/linux/linux_libc_support.cc and none of the other required files.

I'm not sure what happened, but I'm re-uploading the patch has another issue.

Review URL: https://breakpad.appspot.com/426002

git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1002 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
digit@chromium.org
2012-08-03 15:01:52 +00:00
parent 7475fb4bb4
commit e0555f5bdf
10 changed files with 256 additions and 255 deletions

View File

@@ -40,83 +40,21 @@
extern "C" {
static inline size_t
my_strlen(const char* s) {
size_t len = 0;
while (*s++) len++;
return len;
}
extern size_t my_strlen(const char* s);
static inline int
my_strcmp(const char* a, const char* b) {
for (;;) {
if (*a < *b)
return -1;
else if (*a > *b)
return 1;
else if (*a == 0)
return 0;
a++;
b++;
}
}
extern int my_strcmp(const char* a, const char* b);
static inline int
my_strncmp(const char* a, const char* b, size_t len) {
for (size_t i = 0; i < len; ++i) {
if (*a < *b)
return -1;
else if (*a > *b)
return 1;
else if (*a == 0)
return 0;
a++;
b++;
}
return 0;
}
extern int my_strncmp(const char* a, const char* b, size_t len);
// Parse a non-negative integer.
// result: (output) the resulting non-negative integer
// s: a NUL terminated string
// Return true iff successful.
static inline bool
my_strtoui(int* result, const char* s) {
if (*s == 0)
return false;
int r = 0;
for (;; s++) {
if (*s == 0)
break;
const int old_r = r;
r *= 10;
if (*s < '0' || *s > '9')
return false;
r += *s - '0';
if (r < old_r)
return false;
}
*result = r;
return true;
}
extern bool my_strtoui(int* result, const char* s);
// Return the length of the given, non-negative integer when expressed in base
// 10.
static inline unsigned
my_int_len(intmax_t i) {
if (!i)
return 1;
int len = 0;
while (i) {
len++;
i /= 10;
}
return len;
}
extern unsigned my_int_len(intmax_t i);
// Convert a non-negative integer to a string
// output: (output) the resulting string is written here. This buffer must be
@@ -124,54 +62,33 @@ my_int_len(intmax_t i) {
// required length.
// i: the non-negative integer to serialise.
// i_len: the length of the integer in base 10 (see |my_int_len|).
static inline void
my_itos(char* output, intmax_t i, unsigned i_len) {
for (unsigned index = i_len; index; --index, i /= 10)
output[index - 1] = '0' + (i % 10);
}
extern void my_itos(char* output, intmax_t i, unsigned i_len);
static inline const char*
my_strchr(const char* haystack, char needle) {
while (*haystack && *haystack != needle)
haystack++;
if (*haystack == needle)
return haystack;
return (const char*) 0;
}
extern const char* my_strchr(const char* haystack, char needle);
extern const char* my_strrchr(const char* haystack, char needle);
// Read a hex value
// result: (output) the resulting value
// s: a string
// Returns a pointer to the first invalid charactor.
static inline const char*
my_read_hex_ptr(uintptr_t* result, const char* s) {
uintptr_t r = 0;
extern const char* my_read_hex_ptr(uintptr_t* result, const char* s);
for (;; ++s) {
if (*s >= '0' && *s <= '9') {
r <<= 4;
r += *s - '0';
} else if (*s >= 'a' && *s <= 'f') {
r <<= 4;
r += (*s - 'a') + 10;
} else if (*s >= 'A' && *s <= 'F') {
r <<= 4;
r += (*s - 'A') + 10;
} else {
break;
}
}
extern const char* my_read_decimal_ptr(uintptr_t* result, const char* s);
*result = r;
return s;
}
extern void my_memset(void* ip, char c, size_t len);
static inline void
my_memset(void* ip, char c, size_t len) {
char* p = (char *) ip;
while (len--)
*p++ = c;
}
// The following are considered safe to use in a compromised environment.
// Besides, this gives the compiler an opportunity to optimize their calls.
#define my_memcpy memcpy
#define my_memmove memmove
#define my_memcmp memcmp
extern size_t my_strlcpy(char* s1, const char* s2, size_t len);
extern size_t my_strlcat(char* s1, const char* s2, size_t len);
extern int my_isspace(int ch);
} // extern "C"