[BACK]Return to io.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / io

Diff for /OpenXM_contrib2/asir2000/io/io.c between version 1.12 and 1.21

version 1.12, 2003/03/07 06:39:57 version 1.21, 2015/08/19 05:29:23
Line 44 
Line 44 
  * 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.11 2003/03/07 03:12:28 noro Exp $   * $OpenXM: OpenXM_contrib2/asir2000/io/io.c,v 1.20 2015/08/17 05:42:20 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
   
 extern int little_endian,lib_ox_need_conv;  extern int little_endian,lib_ox_need_conv;
 extern int ox_do_copy, ox_do_count, ox_count_length, ox_file_io, ox_need_conv;  extern int ox_do_copy, ox_do_count, ox_count_length, ox_file_io, ox_need_conv;
 extern char *ox_copy_bptr;  extern char *ox_copy_bptr;
   extern int ox_get_pari_result;
   
 /* XXX */  /* XXX */
 void write_cmo(pointer,Obj);  void write_cmo(pointer,Obj);
Line 63  void write_cmo(pointer,Obj);
Line 64  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();
 }  }
   
 void endian_init()  void endian_init()
Line 102  void ox_copy_init(char *s)
Line 104  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 139  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 173  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 212  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);
 }  }
   
 #if defined(VISUAL) && defined(DES_ENC)  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)
 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};
 static unsigned char deskey_string[96];  static unsigned char deskey_string[96];
Line 230  void write_intarray(FILE *f,unsigned int *p,int l)
Line 245  void write_intarray(FILE *f,unsigned int *p,int l)
 {  {
         int i;          int i;
         unsigned int t;          unsigned int t;
 #if defined(VISUAL) && defined(DES_ENC)  #if defined(DES_ENC)
         int l2;          int l2;
         unsigned int plain[2],encrypted[2];          unsigned int plain[2],encrypted[2];
   
Line 263  void write_intarray(FILE *f,unsigned int *p,int l)
Line 278  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 ( l%2 ) {
       w = p[0]; hi = w>>32;
         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++) {        hi = htonl(hi);
                         w = *p; hi = w>>32; lo = w&0xffffffff;      gen_fwrite((char *)&hi,sizeof(unsigned int),1,f);
                         hi = htonl(hi); lo = htonl(lo);      i = 1;
                         gen_fwrite(&hi,sizeof(unsigned int),1,f);    } else
                         gen_fwrite(&lo,sizeof(unsigned int),1,f);      i = 0;
                 }    l = (l+1)/2;
         else    for ( ; i < l; i++ ) {
                 gen_fwrite(p,sizeof(unsigned long),l,f);      w = p[i]; hi = w>>32; lo = w&0xffffffff;
           if ( little_endian && (ox_file_io || ox_need_conv) ) {
         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 345  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;
 #if defined(VISUAL) && defined(DES_ENC)  #if defined(DES_ENC)
         int l2;          int l2;
         unsigned int plain[2],encrypted[2];          unsigned int plain[2],encrypted[2];
   
Line 353  void read_intarray(FILE *f,unsigned int *p,int l)
Line 392  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);            if ( little_endian && (ox_file_io || ox_need_conv) )
                         hi = ntohl(hi); lo = ntohl(lo);              hi = ntohl(hi);
                         *p = (((unsigned long)hi)<<32)|((unsigned long)lo);            *p = (((unsigned long)hi)<<32);
             p++; l--;
           }
           for ( i = 0; i < l; i += 2, p++ ) {
                   gen_fread((char *)&lo,sizeof(unsigned int),1,f);
                   gen_fread((char *)&hi,sizeof(unsigned int),1,f);
               if ( little_endian && (ox_file_io || ox_need_conv) ) {
                 hi = ntohl(hi); lo = ntohl(lo);
                 }                  }
                 if ( i == 1 ) {                  *p = (((unsigned long)hi)<<32)|((unsigned long)lo);
                         gen_fread(&hi,sizeof(unsigned int),1,f);          }
                         hi = ntohl(hi); *p = (((unsigned long)hi)<<32);  
                 }  
         } else  
                 gen_fread(p,sizeof(unsigned int),l,f);  
 }  }
 #endif  #endif
   

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.21

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>