Bug #10019 » pack.patch
D:/rubyinstaller/downloads/ruby_2_1/pack.c Wed Jul 9 09:17:30 2014 | ||
---|---|---|
pack.c -
|
||
$Author: akr $
|
||
$Author: glass $
|
||
created at: Thu Feb 10 15:17:05 JST 1994
|
||
Copyright (C) 1993-2007 Yukihiro Matsumoto
|
||
... | ... | |
#include <sys/types.h>
|
||
#include <ctype.h>
|
||
#include <errno.h>
|
||
#include <malloc.h>
|
||
/*
|
||
* It is intentional that the condition for natstr is HAVE_TRUE_LONG_LONG
|
||
* instead of HAVE_LONG_LONG or LONG_LONG.
|
||
... | ... | |
static void
|
||
encodes(VALUE str, const char *s, long len, int type, int tail_lf)
|
||
{
|
||
char buff[4096];
|
||
long bufLen = len + 128; // enough room
|
||
char* buff = (char*)malloc(bufLen);
|
||
long i = 0;
|
||
const char *trans = type == 'u' ? uu_table : b64_table;
|
||
char padding;
|
||
if (type == 'u') {
|
||
buff[i++] = (char)len + ' ';
|
||
padding = '`';
|
||
buff[i++] = (char)len + ' ';
|
||
padding = '`';
|
||
}
|
||
else {
|
||
padding = '=';
|
||
padding = '=';
|
||
}
|
||
while (len >= 3) {
|
||
while (len >= 3 && sizeof(buff)-i >= 4) {
|
||
while (len >= 3 && bufLen-i >= 4) {
|
||
buff[i++] = trans[077 & (*s >> 2)];
|
||
buff[i++] = trans[077 & (((*s << 4) & 060) | ((s[1] >> 4) & 017))];
|
||
buff[i++] = trans[077 & (((s[1] << 2) & 074) | ((s[2] >> 6) & 03))];
|
||
... | ... | |
s += 3;
|
||
len -= 3;
|
||
}
|
||
if (sizeof(buff)-i < 4) {
|
||
if (bufLen-i < 4) {
|
||
rb_str_buf_cat(str, buff, i);
|
||
i = 0;
|
||
}
|
||
... | ... | |
}
|
||
if (tail_lf) buff[i++] = '\n';
|
||
rb_str_buf_cat(str, buff, i);
|
||
free(buff);
|
||
}
|
||
static const char hex_table[] = "0123456789ABCDEF";
|
||
... | ... | |
s += sizeof(char *);
|
||
if (t) {
|
||
VALUE a, *p, *pend;
|
||
VALUE a;
|
||
const VALUE *p, *pend;
|
||
if (!(a = rb_str_associated(str))) {
|
||
rb_raise(rb_eArgError, "no associated pointer");
|
||
}
|
||
p = RARRAY_PTR(a);
|
||
p = RARRAY_CONST_PTR(a);
|
||
pend = p + RARRAY_LEN(a);
|
||
while (p < pend) {
|
||
if (RB_TYPE_P(*p, T_STRING) && RSTRING_PTR(*p) == t) {
|
||
... | ... | |
s += sizeof(char *);
|
||
if (t) {
|
||
VALUE a, *p, *pend;
|
||
VALUE a;
|
||
const VALUE *p, *pend;
|
||
if (!(a = rb_str_associated(str))) {
|
||
rb_raise(rb_eArgError, "no associated pointer");
|
||
}
|
||
p = RARRAY_PTR(a);
|
||
p = RARRAY_CONST_PTR(a);
|
||
pend = p + RARRAY_LEN(a);
|
||
while (p < pend) {
|
||
if (RB_TYPE_P(*p, T_STRING) && RSTRING_PTR(*p) == t) {
|