version 1.13, 2009/03/13 04:45:16 |
version 1.19, 2015/08/14 13:51:55 |
|
|
* 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.12 2003/03/07 06:39:57 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/io/io.c,v 1.18 2015/08/13 00:13:03 noro Exp $ |
*/ |
*/ |
#include <stdio.h> |
#include <stdio.h> |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
#if defined(VISUAL) || defined(MPI) |
#if defined(VISUAL) || defined(__MINGW32__) || defined(MPI) |
#include "wsio.h" |
#include "wsio.h" |
#endif |
#endif |
|
|
Line 102 void ox_copy_init(char *s) |
|
Line 102 void ox_copy_init(char *s) |
|
ox_copy_bptr = s; |
ox_copy_bptr = s; |
} |
} |
|
|
#if !defined(VISUAL) |
#if !defined(VISUAL) && !defined(__MINGW32__) |
/* |
/* |
* library mode functions |
* library mode functions |
* byte order is controlled by lib_ox_need_conv. |
* byte order is controlled by lib_ox_need_conv. |
Line 137 int gen_fread (char *ptr,int size,int nitems,FILE *str |
|
Line 137 int gen_fread (char *ptr,int size,int nitems,FILE *str |
|
/* dummy return */ |
/* dummy return */ |
return 0; |
return 0; |
} else { |
} else { |
#if defined(VISUAL) |
#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 |
Line 171 int gen_fwrite (char *ptr,int size,int nitems,FILE *st |
|
Line 171 int gen_fwrite (char *ptr,int size,int nitems,FILE *st |
|
/* dummy return */ |
/* dummy return */ |
return 0; |
return 0; |
} else |
} else |
#if defined(VISUAL) |
#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 |
Line 210 void write_int(FILE *f,unsigned int *p) |
|
Line 210 void write_int(FILE *f,unsigned int *p) |
|
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) |
|
{ |
|
unsigned int t; |
|
|
|
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
|
t = htonl(((unsigned int *)p)[1]); |
|
gen_fwrite((char *)&t,sizeof(unsigned int),1,f); |
|
t = htonl(((unsigned int *)p)[0]); |
|
gen_fwrite((char *)&t,sizeof(unsigned int),1,f); |
|
} else |
|
gen_fwrite((char *)p,sizeof(UL),1,f); |
|
} |
|
|
#if defined(DES_ENC) |
#if defined(DES_ENC) |
int des_encryption; |
int des_encryption; |
static unsigned char asir_deskey[8] = {0xc7,0xe0,0xfc,0xb5,0xc3,0xad,0x8e,0x3a}; |
static unsigned char asir_deskey[8] = {0xc7,0xe0,0xfc,0xb5,0xc3,0xad,0x8e,0x3a}; |
Line 263 void write_intarray(FILE *f,unsigned int *p,int l) |
|
Line 276 void write_intarray(FILE *f,unsigned int *p,int l) |
|
gen_fwrite((char *)p,sizeof(unsigned int),l,f); |
gen_fwrite((char *)p,sizeof(unsigned int),l,f); |
} |
} |
|
|
#if defined(LONG_IS_64BIT) |
#if SIZEOF_LONG == 8 |
|
/* write l word (1word=4bytes) */ |
|
/* l even : low 32of p[0] | high32 of p[0] | ... */ |
|
/* l odd : high32 of p[0] | ... */ |
void write_longarray(FILE *f,unsigned long *p,int l) |
void write_longarray(FILE *f,unsigned long *p,int l) |
{ |
{ |
int i; |
int i; |
unsigned long w; |
unsigned long w; |
unsigned int hi,lo; |
unsigned int hi,lo; |
|
|
if ( little_endian && (ox_file_io || ox_need_conv) ) |
if ( l%2 ) { |
for ( i = 0; i < l; i++, p++) { |
w = p[0]; hi = w>>32; |
w = *p; hi = w>>32; lo = w&0xffffffff; |
hi = htonl(hi); |
hi = htonl(hi); lo = htonl(lo); |
gen_fwrite((char *)&hi,sizeof(unsigned int),1,f); |
gen_fwrite(&hi,sizeof(unsigned int),1,f); |
i = 1; |
gen_fwrite(&lo,sizeof(unsigned int),1,f); |
} else |
} |
i = 0; |
else |
l = (l+1)/2; |
gen_fwrite(p,sizeof(unsigned long),l,f); |
for ( ; i < l; i++ ) { |
|
w = p[i]; hi = w>>32; lo = w&0xffffffff; |
|
hi = htonl(hi); lo = htonl(lo); |
|
gen_fwrite((char *)&lo,sizeof(unsigned int),1,f); |
|
gen_fwrite((char *)&hi,sizeof(unsigned int),1,f); |
|
} |
} |
} |
#endif |
#endif |
|
|
Line 319 void read_int(FILE *f,unsigned int *p) |
|
Line 340 void read_int(FILE *f,unsigned int *p) |
|
*p = ntohl(*p); |
*p = ntohl(*p); |
} |
} |
|
|
|
void read_int64(FILE *f,UL *p) |
|
{ |
|
unsigned int t; |
|
|
|
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
|
gen_fread((char *)&t,sizeof(unsigned int),1,f); |
|
((unsigned int *)p)[1] = ntohl(t); |
|
gen_fread((char *)&t,sizeof(unsigned int),1,f); |
|
((unsigned int *)p)[0] = ntohl(t); |
|
} else |
|
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; |
Line 353 void read_intarray(FILE *f,unsigned int *p,int l) |
|
Line 387 void read_intarray(FILE *f,unsigned int *p,int l) |
|
} |
} |
} |
} |
|
|
#if defined(LONG_IS_64BIT) |
#if SIZEOF_LONG == 8 |
|
/* read l word (1word=4bytes) */ |
|
/* pad 0 at low 32 of p[0] if l is odd */ |
|
/* 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; |
|
|
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
q = (unsigned int *)p; |
for ( i = l; i > 1; i -= 2, p++ ) { |
if ( l%2 ) { |
gen_fread(&hi,sizeof(unsigned int),1,f); |
gen_fread((char *)&hi,sizeof(unsigned int),1,f); |
gen_fread(&lo,sizeof(unsigned int),1,f); |
hi = ntohl(hi); |
hi = ntohl(hi); lo = ntohl(lo); |
*p = (((unsigned long)hi)<<32); |
*p = (((unsigned long)hi)<<32)|((unsigned long)lo); |
p++; l--; |
} |
} |
if ( i == 1 ) { |
for ( i = 0; i < l; i += 2, p++ ) { |
gen_fread(&hi,sizeof(unsigned int),1,f); |
gen_fread((char *)&lo,sizeof(unsigned int),1,f); |
hi = ntohl(hi); *p = (((unsigned long)hi)<<32); |
gen_fread((char *)&hi,sizeof(unsigned int),1,f); |
} |
hi = ntohl(hi); lo = ntohl(lo); |
} else |
*p = (((unsigned long)hi)<<32)|((unsigned long)lo); |
gen_fread(p,sizeof(unsigned int),l,f); |
} |
} |
} |
#endif |
#endif |
|
|