Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //====Headers
- #include <iso646.h>
- #include <assert.h>
- #include <limits.h>
- #include <stdbool.h>
- #include <locale.h>
- #include <setjmp.h>
- #include <signal.h>
- #include <stdarg.h>
- #include <stddef.h>
- #include <errno.h>
- #include <ctype.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #include <float.h>
- #include <time.h>
- #include <gmp.h> //using libgmp.a
- #include <mpfr.h>
- //======Types
- #define u1 unsigned char
- #define u2 unsigned short
- #define u4 unsigned int
- #define u8 unsigned long long
- #define s1 signed char
- #define s2 signed short
- #define s4 signed int
- #define s8 signed long long
- #define f2 short float
- #define f4 float
- #define f8 double
- #define f10 long double
- //====Bithacks
- #define setb(o,p) (o|=(1<<p)) //byte| 1<< pos
- #define clrb(o,p) (o&=(~(1<<p))) // byte | 11101111
- #define togb(o,p) (o^=(1<<p))
- #define chkb(o,p) ((o>>p)&1)
- #define bitchar(bitchar_bit) (48|bitchar_bit) // 48|0 or 1
- //====Func
- static __inline__ u8 rdtsc(void){u8 x;
- __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); return x;}
- u8 fsize(u1* filename){
- FILE* tfile=fopen(filename,"rb");
- if(!tfile){perror(filename);return 0;}
- fseek(tfile,0,SEEK_END);
- u8 sz=(u8)(ftell(tfile));fclose(tfile);return sz;}
- u1* getcontent(u1*filename){//file to buffer
- u8 size=fsize(filename);//
- if(!size){perror("Zero length content"); return NULL;}
- u1* res=malloc(size);
- if(!res){perror("Malloc failure");return NULL;}
- FILE* inpfile=fopen(filename,"rb");
- if(!inpfile){perror("File cannot be read");return NULL;}
- u8 findex=(u8)fread(res,1,size,inpfile);fclose(inpfile);
- if(findex!=size){perror("size mismatch");return NULL;}
- return res;}
- void readcontent(u1* filename,u1* storage){
- if(!filename){perror("Invalid filename"); return;}
- u8 inpsize=fsize(filename);
- if(!inpsize){perror("File empty");return;}
- FILE* in=fopen(filename,"rb");
- if(!in){perror(filename);return;}
- storage=realloc(storage,inpsize);
- if(!storage){perror("Malloc failure");return;}
- u8 findex=(u8)fread(storage,1,inpsize,in);
- fclose(in);
- if(findex!=inpsize){perror("Read size mismatch");return;}}
- void writecontent(u1* filename,u1* content,u8 size){
- FILE* out=fopen(filename,"wb");
- if(!out){perror(filename);return;}
- u8 findex=(u8)fwrite(content,1,size,out);fclose(out);
- if(findex!=size) perror("Write size mismatch");}
- void buf2mpz(u1* string,mpz_t num,u8 size){
- if(!string){perror("NULL string");return;}
- if(!num){perror("Invalid mpz_t");return;}
- if(!size){perror("Zero-length string");return;}
- mpz_import(num,size, 1,1, -1, 0,string);
- }
Add Comment
Please, Sign In to add comment