version 1.22, 2017/08/31 09:11:04 |
version 1.23, 2018/03/29 01:32:53 |
|
|
* OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY |
* OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* $OpenXM: OpenXM_contrib2/asir2000/io/io.c,v 1.21 2015/08/19 05:29:23 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/io/io.c,v 1.22 2017/08/31 09:11:04 noro Exp $ |
*/ |
*/ |
#include <stdio.h> |
#include <stdio.h> |
#include "ca.h" |
#include "ca.h" |
Line 63 void write_cmo(pointer,Obj); |
|
Line 63 void write_cmo(pointer,Obj); |
|
|
|
void reset_io() |
void reset_io() |
{ |
{ |
ox_file_io = 0; |
ox_file_io = 0; |
if ( ox_get_pari_result ) reset_ox_pari(); |
if ( ox_get_pari_result ) reset_ox_pari(); |
} |
} |
|
|
void endian_init() |
void endian_init() |
{ |
{ |
unsigned int et = 0xff; |
unsigned int et = 0xff; |
|
|
if ( *((char *)&et) ) |
if ( *((char *)&et) ) |
little_endian = 1; |
little_endian = 1; |
else |
else |
little_endian = 0; |
little_endian = 0; |
ox_need_conv = 1; |
ox_need_conv = 1; |
} |
} |
|
|
int countobj(Obj p) |
int countobj(Obj p) |
{ |
{ |
ox_count_length = 0; |
ox_count_length = 0; |
ox_do_count = 1; saveobj(0,p); ox_do_count = 0; |
ox_do_count = 1; saveobj(0,p); ox_do_count = 0; |
return ox_count_length; |
return ox_count_length; |
} |
} |
|
|
int count_as_cmo(Obj p) |
int count_as_cmo(Obj p) |
{ |
{ |
ox_count_length = 0; |
ox_count_length = 0; |
ox_do_count = 1; write_cmo(0,p); ox_do_count = 0; |
ox_do_count = 1; write_cmo(0,p); ox_do_count = 0; |
return ox_count_length; |
return ox_count_length; |
} |
} |
|
|
int countvl(VL vl) |
int countvl(VL vl) |
{ |
{ |
ox_count_length = 0; |
ox_count_length = 0; |
ox_do_count = 1; savevl(0,vl); ox_do_count = 0; |
ox_do_count = 1; savevl(0,vl); ox_do_count = 0; |
return ox_count_length; |
return ox_count_length; |
} |
} |
|
|
void ox_copy_init(char *s) |
void ox_copy_init(char *s) |
{ |
{ |
ox_copy_bptr = s; |
ox_copy_bptr = s; |
} |
} |
|
|
#if !defined(VISUAL) && !defined(__MINGW32__) |
#if !defined(VISUAL) && !defined(__MINGW32__) |
Line 112 void ox_copy_init(char *s) |
|
Line 112 void ox_copy_init(char *s) |
|
|
|
void ox_obj_to_buf_as_cmo(Obj p) |
void ox_obj_to_buf_as_cmo(Obj p) |
{ |
{ |
ox_need_conv = lib_ox_need_conv; |
ox_need_conv = lib_ox_need_conv; |
ox_do_copy = 1; write_cmo(0,p); ox_do_copy = 0; |
ox_do_copy = 1; write_cmo(0,p); ox_do_copy = 0; |
} |
} |
|
|
void ox_buf_to_obj_as_cmo(Obj *p) |
void ox_buf_to_obj_as_cmo(Obj *p) |
{ |
{ |
ox_need_conv = lib_ox_need_conv; |
ox_need_conv = lib_ox_need_conv; |
ox_do_copy = 1; read_cmo(0,p); ox_do_copy = 0; |
ox_do_copy = 1; read_cmo(0,p); ox_do_copy = 0; |
} |
} |
|
|
void ox_vl_to_buf(VL vl) |
void ox_vl_to_buf(VL vl) |
{ |
{ |
ox_do_copy = 1; savevl(0,vl); ox_do_copy = 0; |
ox_do_copy = 1; savevl(0,vl); ox_do_copy = 0; |
} |
} |
#endif |
#endif |
|
|
int gen_fread (char *ptr,int size,int nitems,FILE *stream) |
int gen_fread (char *ptr,int size,int nitems,FILE *stream) |
{ |
{ |
int n; |
int n; |
|
|
if ( ox_do_copy ) { |
if ( ox_do_copy ) { |
n = size*nitems; |
n = size*nitems; |
memcpy(ptr,ox_copy_bptr,n); |
memcpy(ptr,ox_copy_bptr,n); |
ox_copy_bptr += n; |
ox_copy_bptr += n; |
/* dummy return */ |
/* dummy return */ |
return 0; |
return 0; |
} else { |
} else { |
#if defined(VISUAL) || defined(__MINGW32__) |
#if defined(VISUAL) || defined(__MINGW32__) |
if ( _fileno(stream) < 0 ) |
if ( _fileno(stream) < 0 ) |
n = cread(ptr,size,nitems,(STREAM *)stream); |
n = cread(ptr,size,nitems,(STREAM *)stream); |
else |
else |
#elif defined(MPI) |
#elif defined(MPI) |
if ( (char)fileno(stream) < 0 ) |
if ( (char)fileno(stream) < 0 ) |
n = cread(ptr,size,nitems,(STREAM *)stream); |
n = cread(ptr,size,nitems,(STREAM *)stream); |
else |
else |
#endif |
#endif |
n = fread(ptr,size,nitems,stream); |
n = fread(ptr,size,nitems,stream); |
if ( !n ) { |
if ( !n ) { |
ExitAsir(); |
ExitAsir(); |
/* NOTREACHED */ |
/* NOTREACHED */ |
return 0; |
return 0; |
} else |
} else |
return n; |
return n; |
} |
} |
} |
} |
|
|
int gen_fwrite (char *ptr,int size,int nitems,FILE *stream) |
int gen_fwrite (char *ptr,int size,int nitems,FILE *stream) |
{ |
{ |
int n; |
int n; |
|
|
if ( ox_do_count ) { |
if ( ox_do_count ) { |
ox_count_length += size*nitems; |
ox_count_length += size*nitems; |
/* dummy return */ |
/* dummy return */ |
return 0; |
return 0; |
} else if ( ox_do_copy ) { |
} else if ( ox_do_copy ) { |
n = size*nitems; |
n = size*nitems; |
memcpy(ox_copy_bptr,ptr,n); |
memcpy(ox_copy_bptr,ptr,n); |
ox_copy_bptr += n; |
ox_copy_bptr += n; |
/* dummy return */ |
/* dummy return */ |
return 0; |
return 0; |
} else |
} else |
#if defined(VISUAL) || defined(__MINGW32__) |
#if defined(VISUAL) || defined(__MINGW32__) |
if ( _fileno(stream) < 0 ) |
if ( _fileno(stream) < 0 ) |
return cwrite(ptr,size,nitems,(STREAM *)stream); |
return cwrite(ptr,size,nitems,(STREAM *)stream); |
else |
else |
#elif defined(MPI) |
#elif defined(MPI) |
if ( (char)fileno(stream) < 0 ) |
if ( (char)fileno(stream) < 0 ) |
return cwrite(ptr,size,nitems,(STREAM *)stream); |
return cwrite(ptr,size,nitems,(STREAM *)stream); |
else |
else |
#endif |
#endif |
return fwrite(ptr,size,nitems,stream); |
return fwrite(ptr,size,nitems,stream); |
} |
} |
|
|
void write_char(FILE *f,unsigned char *p) |
void write_char(FILE *f,unsigned char *p) |
{ |
{ |
gen_fwrite(p,sizeof(unsigned char),1,f); |
gen_fwrite(p,sizeof(unsigned char),1,f); |
} |
} |
|
|
void write_short(FILE *f,unsigned short *p) |
void write_short(FILE *f,unsigned short *p) |
{ |
{ |
unsigned short t; |
unsigned short t; |
|
|
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
t = htons(*p); |
t = htons(*p); |
gen_fwrite((char *)&t,sizeof(unsigned short),1,f); |
gen_fwrite((char *)&t,sizeof(unsigned short),1,f); |
} else |
} else |
gen_fwrite((char *)p,sizeof(unsigned short),1,f); |
gen_fwrite((char *)p,sizeof(unsigned short),1,f); |
} |
} |
|
|
void write_int(FILE *f,unsigned int *p) |
void write_int(FILE *f,unsigned int *p) |
{ |
{ |
unsigned int t; |
unsigned int t; |
|
|
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
t = htonl(*p); |
t = htonl(*p); |
gen_fwrite((char *)&t,sizeof(unsigned int),1,f); |
gen_fwrite((char *)&t,sizeof(unsigned int),1,f); |
} else |
} else |
gen_fwrite((char *)p,sizeof(unsigned int),1,f); |
gen_fwrite((char *)p,sizeof(unsigned int),1,f); |
} |
} |
|
|
void write_int64(FILE *f,UL *p) |
void write_int64(FILE *f,UL *p) |
{ |
{ |
unsigned int t; |
unsigned int t; |
|
|
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
t = htonl(((unsigned int *)p)[1]); |
t = htonl(((unsigned int *)p)[1]); |
gen_fwrite((char *)&t,sizeof(unsigned int),1,f); |
gen_fwrite((char *)&t,sizeof(unsigned int),1,f); |
t = htonl(((unsigned int *)p)[0]); |
t = htonl(((unsigned int *)p)[0]); |
gen_fwrite((char *)&t,sizeof(unsigned int),1,f); |
gen_fwrite((char *)&t,sizeof(unsigned int),1,f); |
} else |
} else |
gen_fwrite((char *)p,sizeof(UL),1,f); |
gen_fwrite((char *)p,sizeof(UL),1,f); |
} |
} |
|
|
#if defined(DES_ENC) |
#if defined(DES_ENC) |
Line 232 static unsigned char deskey_string[96]; |
|
Line 232 static unsigned char deskey_string[96]; |
|
|
|
void init_deskey() |
void init_deskey() |
{ |
{ |
static int deskey_initialized = 0; |
static int deskey_initialized = 0; |
|
|
if ( !deskey_initialized ) { |
if ( !deskey_initialized ) { |
key_schedule(asir_deskey,deskey_string); |
key_schedule(asir_deskey,deskey_string); |
deskey_initialized = 1; |
deskey_initialized = 1; |
} |
} |
} |
} |
#endif |
#endif |
|
|
void write_intarray(FILE *f,unsigned int *p,int l) |
void write_intarray(FILE *f,unsigned int *p,int l) |
{ |
{ |
int i; |
int i; |
unsigned int t; |
unsigned int t; |
#if defined(DES_ENC) |
#if defined(DES_ENC) |
int l2; |
int l2; |
unsigned int plain[2],encrypted[2]; |
unsigned int plain[2],encrypted[2]; |
|
|
if ( des_encryption ) { |
if ( des_encryption ) { |
l2 = l>>1; |
l2 = l>>1; |
for ( i = 0; i < l2; i++ ) { |
for ( i = 0; i < l2; i++ ) { |
plain[0] = *p++; |
plain[0] = *p++; |
plain[1] = *p++; |
plain[1] = *p++; |
des_enc(plain,deskey_string,encrypted); |
des_enc(plain,deskey_string,encrypted); |
encrypted[0] = htonl(encrypted[0]); |
encrypted[0] = htonl(encrypted[0]); |
encrypted[1] = htonl(encrypted[1]); |
encrypted[1] = htonl(encrypted[1]); |
gen_fwrite((char *)encrypted,sizeof(unsigned int),2,f); |
gen_fwrite((char *)encrypted,sizeof(unsigned int),2,f); |
} |
} |
if ( (l2<<1) < l ) { |
if ( (l2<<1) < l ) { |
plain[0] = *p; |
plain[0] = *p; |
plain[1] = 0; |
plain[1] = 0; |
des_enc(plain,deskey_string,encrypted); |
des_enc(plain,deskey_string,encrypted); |
encrypted[0] = htonl(encrypted[0]); |
encrypted[0] = htonl(encrypted[0]); |
encrypted[1] = htonl(encrypted[1]); |
encrypted[1] = htonl(encrypted[1]); |
gen_fwrite((char *)encrypted,sizeof(unsigned int),2,f); |
gen_fwrite((char *)encrypted,sizeof(unsigned int),2,f); |
} |
} |
} else |
} else |
#endif |
#endif |
if ( little_endian && (ox_file_io || ox_need_conv) ) |
if ( little_endian && (ox_file_io || ox_need_conv) ) |
for ( i = 0; i < l; i++, p++) { |
for ( i = 0; i < l; i++, p++) { |
t = htonl(*p); |
t = htonl(*p); |
gen_fwrite((char *)&t,sizeof(unsigned int),1,f); |
gen_fwrite((char *)&t,sizeof(unsigned int),1,f); |
} |
} |
else |
else |
gen_fwrite((char *)p,sizeof(unsigned int),l,f); |
gen_fwrite((char *)p,sizeof(unsigned int),l,f); |
} |
} |
|
|
#if SIZEOF_LONG == 8 |
#if SIZEOF_LONG == 8 |
Line 290 void write_longarray(FILE *f,unsigned long *p,int l) |
|
Line 290 void write_longarray(FILE *f,unsigned long *p,int l) |
|
|
|
if ( l%2 ) { |
if ( l%2 ) { |
w = p[0]; hi = w>>32; |
w = p[0]; hi = w>>32; |
if ( little_endian && (ox_file_io || ox_need_conv) ) |
if ( little_endian && (ox_file_io || ox_need_conv) ) |
hi = htonl(hi); |
hi = htonl(hi); |
gen_fwrite((char *)&hi,sizeof(unsigned int),1,f); |
gen_fwrite((char *)&hi,sizeof(unsigned int),1,f); |
i = 1; |
i = 1; |
Line 299 void write_longarray(FILE *f,unsigned long *p,int l) |
|
Line 299 void write_longarray(FILE *f,unsigned long *p,int l) |
|
l = (l+1)/2; |
l = (l+1)/2; |
for ( ; i < l; i++ ) { |
for ( ; i < l; i++ ) { |
w = p[i]; hi = w>>32; lo = w&0xffffffff; |
w = p[i]; hi = w>>32; lo = w&0xffffffff; |
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
hi = htonl(hi); lo = htonl(lo); |
hi = htonl(hi); lo = htonl(lo); |
} |
} |
gen_fwrite((char *)&lo,sizeof(unsigned int),1,f); |
gen_fwrite((char *)&lo,sizeof(unsigned int),1,f); |
gen_fwrite((char *)&hi,sizeof(unsigned int),1,f); |
gen_fwrite((char *)&hi,sizeof(unsigned int),1,f); |
} |
} |
Line 320 void write_longarray(FILE *f,unsigned long long *p,int |
|
Line 320 void write_longarray(FILE *f,unsigned long long *p,int |
|
|
|
if ( l%2 ) { |
if ( l%2 ) { |
w = p[0]; hi = w>>32; |
w = p[0]; hi = w>>32; |
if ( little_endian && (ox_file_io || ox_need_conv) ) |
if ( little_endian && (ox_file_io || ox_need_conv) ) |
hi = htonl(hi); |
hi = htonl(hi); |
gen_fwrite((char *)&hi,sizeof(unsigned int),1,f); |
gen_fwrite((char *)&hi,sizeof(unsigned int),1,f); |
i = 1; |
i = 1; |
Line 329 void write_longarray(FILE *f,unsigned long long *p,int |
|
Line 329 void write_longarray(FILE *f,unsigned long long *p,int |
|
l = (l+1)/2; |
l = (l+1)/2; |
for ( ; i < l; i++ ) { |
for ( ; i < l; i++ ) { |
w = p[i]; hi = w>>32; lo = w&0xffffffff; |
w = p[i]; hi = w>>32; lo = w&0xffffffff; |
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
hi = htonl(hi); lo = htonl(lo); |
hi = htonl(hi); lo = htonl(lo); |
} |
} |
gen_fwrite((char *)&lo,sizeof(unsigned int),1,f); |
gen_fwrite((char *)&lo,sizeof(unsigned int),1,f); |
gen_fwrite((char *)&hi,sizeof(unsigned int),1,f); |
gen_fwrite((char *)&hi,sizeof(unsigned int),1,f); |
} |
} |
Line 340 void write_longarray(FILE *f,unsigned long long *p,int |
|
Line 340 void write_longarray(FILE *f,unsigned long long *p,int |
|
|
|
void write_double(FILE *f,double *p) |
void write_double(FILE *f,double *p) |
{ |
{ |
unsigned int t; |
unsigned int t; |
|
|
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
t = htonl(((unsigned int *)p)[1]); |
t = htonl(((unsigned int *)p)[1]); |
gen_fwrite((char *)&t,sizeof(unsigned int),1,f); |
gen_fwrite((char *)&t,sizeof(unsigned int),1,f); |
t = htonl(((unsigned int *)p)[0]); |
t = htonl(((unsigned int *)p)[0]); |
gen_fwrite((char *)&t,sizeof(unsigned int),1,f); |
gen_fwrite((char *)&t,sizeof(unsigned int),1,f); |
} else |
} else |
gen_fwrite((char *)p,sizeof(double),1,f); |
gen_fwrite((char *)p,sizeof(double),1,f); |
} |
} |
|
|
void write_string(FILE *f,unsigned char *p,int l) |
void write_string(FILE *f,unsigned char *p,int l) |
{ |
{ |
gen_fwrite(p,sizeof(unsigned char),l,f); |
gen_fwrite(p,sizeof(unsigned char),l,f); |
} |
} |
|
|
void read_char(FILE *f,unsigned char *p) |
void read_char(FILE *f,unsigned char *p) |
{ |
{ |
gen_fread((char *)p,sizeof(unsigned char),1,f); |
gen_fread((char *)p,sizeof(unsigned char),1,f); |
} |
} |
|
|
void read_short(FILE *f,unsigned short *p) |
void read_short(FILE *f,unsigned short *p) |
{ |
{ |
gen_fread((char *)p,sizeof(unsigned short),1,f); |
gen_fread((char *)p,sizeof(unsigned short),1,f); |
if ( little_endian && (ox_file_io || ox_need_conv) ) |
if ( little_endian && (ox_file_io || ox_need_conv) ) |
*p = ntohs(*p); |
*p = ntohs(*p); |
} |
} |
|
|
void read_int(FILE *f,unsigned int *p) |
void read_int(FILE *f,unsigned int *p) |
{ |
{ |
gen_fread((char *)p,sizeof(unsigned int),1,f); |
gen_fread((char *)p,sizeof(unsigned int),1,f); |
if ( little_endian && (ox_file_io || ox_need_conv) ) |
if ( little_endian && (ox_file_io || ox_need_conv) ) |
*p = ntohl(*p); |
*p = ntohl(*p); |
} |
} |
|
|
void read_int64(FILE *f,UL *p) |
void read_int64(FILE *f,UL *p) |
{ |
{ |
unsigned int t; |
unsigned int t; |
|
|
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
gen_fread((char *)&t,sizeof(unsigned int),1,f); |
gen_fread((char *)&t,sizeof(unsigned int),1,f); |
((unsigned int *)p)[1] = ntohl(t); |
((unsigned int *)p)[1] = ntohl(t); |
gen_fread((char *)&t,sizeof(unsigned int),1,f); |
gen_fread((char *)&t,sizeof(unsigned int),1,f); |
((unsigned int *)p)[0] = ntohl(t); |
((unsigned int *)p)[0] = ntohl(t); |
} else |
} else |
gen_fread((char *)p,sizeof(UL),1,f); |
gen_fread((char *)p,sizeof(UL),1,f); |
} |
} |
|
|
void read_intarray(FILE *f,unsigned int *p,int l) |
void read_intarray(FILE *f,unsigned int *p,int l) |
{ |
{ |
int i; |
int i; |
#if defined(DES_ENC) |
#if defined(DES_ENC) |
int l2; |
int l2; |
unsigned int plain[2],encrypted[2]; |
unsigned int plain[2],encrypted[2]; |
|
|
if ( des_encryption ) { |
if ( des_encryption ) { |
l2 = l>>1; |
l2 = l>>1; |
for ( i = 0; i < l2; i++ ) { |
for ( i = 0; i < l2; i++ ) { |
gen_fread((char *)encrypted,sizeof(unsigned int),2,f); |
gen_fread((char *)encrypted,sizeof(unsigned int),2,f); |
encrypted[0] = ntohl(encrypted[0]); |
encrypted[0] = ntohl(encrypted[0]); |
encrypted[1] = ntohl(encrypted[1]); |
encrypted[1] = ntohl(encrypted[1]); |
des_dec(encrypted,deskey_string,plain); |
des_dec(encrypted,deskey_string,plain); |
*p++ = plain[0]; |
*p++ = plain[0]; |
*p++ = plain[1]; |
*p++ = plain[1]; |
} |
} |
if ( (l2<<1) < l ) { |
if ( (l2<<1) < l ) { |
gen_fread((char *)encrypted,sizeof(unsigned int),2,f); |
gen_fread((char *)encrypted,sizeof(unsigned int),2,f); |
encrypted[0] = ntohl(encrypted[0]); |
encrypted[0] = ntohl(encrypted[0]); |
encrypted[1] = ntohl(encrypted[1]); |
encrypted[1] = ntohl(encrypted[1]); |
des_dec(encrypted,deskey_string,plain); |
des_dec(encrypted,deskey_string,plain); |
*p = plain[0]; |
*p = plain[0]; |
} |
} |
} else |
} else |
#endif |
#endif |
{ |
{ |
gen_fread((char *)p,sizeof(unsigned int),l,f); |
gen_fread((char *)p,sizeof(unsigned int),l,f); |
if ( little_endian && (ox_file_io || ox_need_conv) ) |
if ( little_endian && (ox_file_io || ox_need_conv) ) |
for ( i = 0; i < l; i++, p++ ) |
for ( i = 0; i < l; i++, p++ ) |
*p = ntohl(*p); |
*p = ntohl(*p); |
} |
} |
} |
} |
|
|
#if SIZEOF_LONG == 8 |
#if SIZEOF_LONG == 8 |
Line 428 void read_intarray(FILE *f,unsigned int *p,int l) |
|
Line 428 void read_intarray(FILE *f,unsigned int *p,int l) |
|
/* low 32 of p[0] | high32 of p[0] | ... */ |
/* low 32 of p[0] | high32 of p[0] | ... */ |
void read_longarray(FILE *f,unsigned long *p,int l) |
void read_longarray(FILE *f,unsigned long *p,int l) |
{ |
{ |
int i; |
int i; |
unsigned int hi,lo; |
unsigned int hi,lo; |
unsigned int *q; |
unsigned int *q; |
|
|
q = (unsigned int *)p; |
q = (unsigned int *)p; |
if ( l%2 ) { |
if ( l%2 ) { |
gen_fread((char *)&hi,sizeof(unsigned int),1,f); |
gen_fread((char *)&hi,sizeof(unsigned int),1,f); |
if ( little_endian && (ox_file_io || ox_need_conv) ) |
if ( little_endian && (ox_file_io || ox_need_conv) ) |
hi = ntohl(hi); |
hi = ntohl(hi); |
*p = (((unsigned long)hi)<<32); |
*p = (((unsigned long)hi)<<32); |
p++; l--; |
p++; l--; |
} |
} |
for ( i = 0; i < l; i += 2, p++ ) { |
for ( i = 0; i < l; i += 2, p++ ) { |
gen_fread((char *)&lo,sizeof(unsigned int),1,f); |
gen_fread((char *)&lo,sizeof(unsigned int),1,f); |
gen_fread((char *)&hi,sizeof(unsigned int),1,f); |
gen_fread((char *)&hi,sizeof(unsigned int),1,f); |
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
hi = ntohl(hi); lo = ntohl(lo); |
hi = ntohl(hi); lo = ntohl(lo); |
} |
} |
*p = (((unsigned long)hi)<<32)|((unsigned long)lo); |
*p = (((unsigned long)hi)<<32)|((unsigned long)lo); |
} |
} |
} |
} |
#endif |
#endif |
|
|
Line 457 void read_longarray(FILE *f,unsigned long *p,int l) |
|
Line 457 void read_longarray(FILE *f,unsigned long *p,int l) |
|
/* low 32 of p[0] | high32 of p[0] | ... */ |
/* low 32 of p[0] | high32 of p[0] | ... */ |
void read_longarray(FILE *f,unsigned long long *p,int l) |
void read_longarray(FILE *f,unsigned long long *p,int l) |
{ |
{ |
int i; |
int i; |
unsigned int hi,lo; |
unsigned int hi,lo; |
unsigned int *q; |
unsigned int *q; |
|
|
q = (unsigned int *)p; |
q = (unsigned int *)p; |
if ( l%2 ) { |
if ( l%2 ) { |
gen_fread((char *)&hi,sizeof(unsigned int),1,f); |
gen_fread((char *)&hi,sizeof(unsigned int),1,f); |
if ( little_endian && (ox_file_io || ox_need_conv) ) |
if ( little_endian && (ox_file_io || ox_need_conv) ) |
hi = ntohl(hi); |
hi = ntohl(hi); |
*p = (((unsigned long long)hi)<<32); |
*p = (((unsigned long long)hi)<<32); |
p++; l--; |
p++; l--; |
} |
} |
for ( i = 0; i < l; i += 2, p++ ) { |
for ( i = 0; i < l; i += 2, p++ ) { |
gen_fread((char *)&lo,sizeof(unsigned int),1,f); |
gen_fread((char *)&lo,sizeof(unsigned int),1,f); |
gen_fread((char *)&hi,sizeof(unsigned int),1,f); |
gen_fread((char *)&hi,sizeof(unsigned int),1,f); |
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
hi = ntohl(hi); lo = ntohl(lo); |
hi = ntohl(hi); lo = ntohl(lo); |
} |
} |
*p = (((unsigned long long)hi)<<32)|((unsigned long long)lo); |
*p = (((unsigned long long)hi)<<32)|((unsigned long long)lo); |
} |
} |
} |
} |
#endif |
#endif |
|
|
void read_string(FILE *f,unsigned char *p,int l) |
void read_string(FILE *f,unsigned char *p,int l) |
{ |
{ |
gen_fread((char *)p,sizeof(unsigned char),l,f); |
gen_fread((char *)p,sizeof(unsigned char),l,f); |
} |
} |
|
|
void read_double(FILE *f,double *p) |
void read_double(FILE *f,double *p) |
{ |
{ |
unsigned int t; |
unsigned int t; |
|
|
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
gen_fread((char *)&t,sizeof(unsigned int),1,f); |
gen_fread((char *)&t,sizeof(unsigned int),1,f); |
((unsigned int *)p)[1] = ntohl(t); |
((unsigned int *)p)[1] = ntohl(t); |
gen_fread((char *)&t,sizeof(unsigned int),1,f); |
gen_fread((char *)&t,sizeof(unsigned int),1,f); |
((unsigned int *)p)[0] = ntohl(t); |
((unsigned int *)p)[0] = ntohl(t); |
} else |
} else |
gen_fread((char *)p,sizeof(double),1,f); |
gen_fread((char *)p,sizeof(double),1,f); |
} |
} |