ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

dlltest.c
Go to the documentation of this file.
00001 /*
00002    minibz2
00003       libbz2.dll test program.
00004       by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp)
00005       This file is Public Domain.  Welcome any email to me.
00006 
00007    usage: minibz2 [-d] [-{1,2,..9}] [[srcfilename] destfilename]
00008 */
00009 
00010 #define BZ_IMPORT
00011 #include <stdio.h>
00012 #include <stdlib.h>
00013 #include "bzlib.h"
00014 #ifdef _WIN32
00015 #include <io.h>
00016 #endif
00017 
00018 
00019 #ifdef _WIN32
00020 
00021 #define BZ2_LIBNAME "libbz2-1.0.2.DLL" 
00022 
00023 #include <windows.h>
00024 static int BZ2DLLLoaded = 0;
00025 static HINSTANCE BZ2DLLhLib;
00026 int BZ2DLLLoadLibrary(void)
00027 {
00028    HINSTANCE hLib;
00029 
00030    if(BZ2DLLLoaded==1){return 0;}
00031    hLib=LoadLibrary(BZ2_LIBNAME);
00032    if(hLib == NULL){
00033       fprintf(stderr,"Can't load %s\n",BZ2_LIBNAME);
00034       return -1;
00035    }
00036    BZ2_bzlibVersion=GetProcAddress(hLib,"BZ2_bzlibVersion");
00037    BZ2_bzopen=GetProcAddress(hLib,"BZ2_bzopen");
00038    BZ2_bzdopen=GetProcAddress(hLib,"BZ2_bzdopen");
00039    BZ2_bzread=GetProcAddress(hLib,"BZ2_bzread");
00040    BZ2_bzwrite=GetProcAddress(hLib,"BZ2_bzwrite");
00041    BZ2_bzflush=GetProcAddress(hLib,"BZ2_bzflush");
00042    BZ2_bzclose=GetProcAddress(hLib,"BZ2_bzclose");
00043    BZ2_bzerror=GetProcAddress(hLib,"BZ2_bzerror");
00044 
00045    if (!BZ2_bzlibVersion || !BZ2_bzopen || !BZ2_bzdopen
00046        || !BZ2_bzread || !BZ2_bzwrite || !BZ2_bzflush
00047        || !BZ2_bzclose || !BZ2_bzerror) {
00048       fprintf(stderr,"GetProcAddress failed.\n");
00049       return -1;
00050    }
00051    BZ2DLLLoaded=1;
00052    BZ2DLLhLib=hLib;
00053    return 0;
00054 
00055 }
00056 int BZ2DLLFreeLibrary(void)
00057 {
00058    if(BZ2DLLLoaded==0){return 0;}
00059    FreeLibrary(BZ2DLLhLib);
00060    BZ2DLLLoaded=0;
00061 }
00062 #endif /* WIN32 */
00063 
00064 void usage(void)
00065 {
00066    puts("usage: minibz2 [-d] [-{1,2,..9}] [[srcfilename] destfilename]");
00067 }
00068 
00069 int main(int argc,char *argv[])
00070 {
00071    int decompress = 0;
00072    int level = 9;
00073    char *fn_r = NULL;
00074    char *fn_w = NULL;
00075 
00076 #ifdef _WIN32
00077    if(BZ2DLLLoadLibrary()<0){
00078       fprintf(stderr,"Loading of %s failed.  Giving up.\n", BZ2_LIBNAME);
00079       exit(1);
00080    }
00081    printf("Loading of %s succeeded.  Library version is %s.\n",
00082           BZ2_LIBNAME, BZ2_bzlibVersion() );
00083 #endif
00084    while(++argv,--argc){
00085       if(**argv =='-' || **argv=='/'){
00086          char *p;
00087 
00088          for(p=*argv+1;*p;p++){
00089             if(*p=='d'){
00090                decompress = 1;
00091             }else if('1'<=*p && *p<='9'){
00092                level = *p - '0';
00093             }else{
00094                usage();
00095                exit(1);
00096             }
00097          }
00098       }else{
00099          break;
00100       }
00101    }
00102    if(argc>=1){
00103       fn_r = *argv;
00104       argc--;argv++;
00105    }else{
00106       fn_r = NULL;
00107    }
00108    if(argc>=1){
00109       fn_w = *argv;
00110       argc--;argv++;
00111    }else{
00112       fn_w = NULL;
00113    }
00114    {
00115       int len;
00116       char buff[0x1000];
00117       char mode[10];
00118 
00119       if(decompress){
00120          BZFILE *BZ2fp_r = NULL;
00121          FILE *fp_w = NULL;
00122 
00123          if(fn_w){
00124             if((fp_w = fopen(fn_w,"wb"))==NULL){
00125                printf("can't open [%s]\n",fn_w);
00126                perror("reason:");
00127                exit(1);
00128             }
00129          }else{
00130             fp_w = stdout;
00131          }
00132          if((fn_r == NULL && (BZ2fp_r = BZ2_bzdopen(fileno(stdin),"rb"))==NULL)
00133             || (fn_r != NULL && (BZ2fp_r = BZ2_bzopen(fn_r,"rb"))==NULL)){
00134             printf("can't bz2openstream\n");
00135             exit(1);
00136          }
00137          while((len=BZ2_bzread(BZ2fp_r,buff,0x1000))>0){
00138             fwrite(buff,1,len,fp_w);
00139          }
00140          BZ2_bzclose(BZ2fp_r);
00141          if(fp_w != stdout) fclose(fp_w);
00142       }else{
00143          BZFILE *BZ2fp_w = NULL;
00144          FILE *fp_r = NULL;
00145 
00146          if(fn_r){
00147             if((fp_r = fopen(fn_r,"rb"))==NULL){
00148                printf("can't open [%s]\n",fn_r);
00149                perror("reason:");
00150                exit(1);
00151             }
00152          }else{
00153             fp_r = stdin;
00154          }
00155          mode[0]='w';
00156          mode[1] = '0' + level;
00157          mode[2] = '\0';
00158 
00159          if((fn_w == NULL && (BZ2fp_w = BZ2_bzdopen(fileno(stdout),mode))==NULL)
00160             || (fn_w !=NULL && (BZ2fp_w = BZ2_bzopen(fn_w,mode))==NULL)){
00161             printf("can't bz2openstream\n");
00162             exit(1);
00163          }
00164          while((len=fread(buff,1,0x1000,fp_r))>0){
00165             BZ2_bzwrite(BZ2fp_w,buff,len);
00166          }
00167          BZ2_bzclose(BZ2fp_w);
00168          if(fp_r!=stdin)fclose(fp_r);
00169       }
00170    }
00171 #ifdef _WIN32
00172    BZ2DLLFreeLibrary();
00173 #endif
00174    return 0;
00175 }

Generated on Sat May 26 2012 04:32:19 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.