random small size optimizations

This commit is contained in:
Denis Vlasenko
2007-01-12 22:10:34 +00:00
parent 21b080daa8
commit 3a34d0c08a
8 changed files with 34 additions and 23 deletions

View File

@@ -28,6 +28,7 @@ const char bb_msg_standard_input[] = "standard input";
const char bb_msg_standard_output[] = "standard output";
const char bb_str_default[] = "default";
const char bb_hexdigits_upcase[] = "0123456789ABCDEF";
const char bb_path_passwd_file[] = "/etc/passwd";
const char bb_path_shadow_file[] = "/etc/shadow";

View File

@@ -88,7 +88,7 @@ char *reads(int fd, char *buffer, size_t size)
*p++ = '\0';
// avoid incorrect (unsigned) widening
offset = (off_t)(p-buffer) - (off_t)size;
// set fd position the right after the \n
// set fd position right after '\n'
if (offset && lseek(fd, offset, SEEK_CUR) == (off_t)-1)
return NULL;
}

View File

@@ -333,6 +333,19 @@ char *itoa(int n)
return local_buf;
}
// Emit a string of hex representation of bytes
char *bin2hex(char *p, const char *cp, int count)
{
while (count) {
unsigned char c = *cp++;
/* put lowercase hex digits */
*p++ = 0x10 | bb_hexdigits_upcase[c >> 4];
*p++ = 0x10 | bb_hexdigits_upcase[c & 0xf];
count--;
}
return p;
}
// Die with an error message if we can't set gid. (Because resource limits may
// limit this user to a given number of processes, and if that fills up the
// setgid() will fail and we'll _still_be_root_, which is bad.)