Example #1
0
LUAMOD_API int luaopen_larc_bzip2(lua_State *L)
{
	luaL_newmetatable(L, BZ2COMPRESS_MT);
	lua_pushcfunction(L, compress_userdata_gc);
	lua_setfield(L, -2, "__gc");
	lua_pop(L, 1);
	luaL_newmetatable(L, BZ2DECOMPRESS_MT);
	lua_pushcfunction(L, decompress_userdata_gc);
	lua_setfield(L, -2, "__gc");
	lua_pop(L, 1);
	luaL_register(L, "larc.bzip2", larc_bzip2_Reg);
	lua_pushstring(L, BZ2_bzlibVersion());
	lua_setfield(L, -2, "BZLIB_VERSION");
	SETCONSTANT(BZ_OK);
	SETCONSTANT(BZ_STREAM_END);
	SETCONSTANT(BZ_CONFIG_ERROR);
	SETCONSTANT(BZ_SEQUENCE_ERROR);
	SETCONSTANT(BZ_PARAM_ERROR);
	SETCONSTANT(BZ_DATA_ERROR);
	SETCONSTANT(BZ_MEM_ERROR);
	SETCONSTANT(BZ_IO_ERROR);
	SETCONSTANT(BZ_DATA_ERROR_MAGIC);
	SETCONSTANT(BZ_UNEXPECTED_EOF);
	SETCONSTANT(BZ_OUTBUFF_FULL);
	return 1;
}
Example #2
0
const char *
archive_version_details(void)
{
	static struct archive_string str;
	static int init = 0;

	if (!init) {
		archive_string_init(&str);

		archive_strcat(&str, ARCHIVE_VERSION_STRING);
#ifdef HAVE_ZLIB_H
		archive_strcat(&str, " zlib/");
		archive_strcat(&str, ZLIB_VERSION);
#endif
#ifdef HAVE_LZMA_H
		archive_strcat(&str, " liblzma/");
		archive_strcat(&str, LZMA_VERSION_STRING);
#endif
#ifdef HAVE_BZLIB_H
		{
			const char *p = BZ2_bzlibVersion();
			const char *sep = strchr(p, ',');
			if (sep == NULL)
				sep = p + strlen(p);
			archive_strcat(&str, " bz2lib/");
			archive_strncat(&str, p, sep - p);
		}
#endif
#if defined(HAVE_LZ4_H) && defined(HAVE_LIBLZ4)
		archive_string_sprintf(&str, " liblz4/%d.%d.%d",
		    LZ4_VERSION_MAJOR, LZ4_VERSION_MINOR, LZ4_VERSION_RELEASE);
#endif
	}
	return str.s;
}
Example #3
0
int main()
{
    const char *ver = BZ2_bzlibVersion();
    // char *ver = BZ2_bzlibVersion();
    printf("%s\n", ver); 
    // printf("%s\n", BZ_VERSION); 
    return 0;
}
LIBSBML_EXTERN
const char* 
getLibSBMLDependencyVersionOf(const char* option)
{
  if (option == NULL) return NULL;
  
  if (strcmp(option, "expat") == 0)
  {
#ifdef USE_EXPAT
    return static_cast<const char*>(XML_ExpatVersion());
#else
    return NULL;
#endif
  }

  if (strcmp(option, "libxml") == 0 ||
    strcmp(option, "libxml2") == 0)
  {
#ifdef USE_LIBXML
    return LIBXML_DOTTED_VERSION;
#else
    return NULL;
#endif
  }

  if (strcmp(option, "xerces-c") == 0 ||
    strcmp(option, "xercesc") == 0)
  {
#ifdef USE_XERCES
    return XERCES_FULLVERSIONDOT;
#else
    return NULL;
#endif
  }

  if (strcmp(option, "zlib") == 0 ||
    strcmp(option, "zip") == 0)
  {
#ifdef USE_ZLIB
    return ZLIB_VERSION;
#else
    return NULL;
#endif
  }

  if (strcmp(option, "bzip") == 0 ||
    strcmp(option, "bzip2") == 0 ||
    strcmp(option, "bz2") == 0)
  {
#ifdef USE_BZ2
    return BZ2_bzlibVersion();
#else
    return NULL;
#endif
  }

  return NULL;
}
Example #5
0
const char *
archive_bzlib_version(void)
{
#ifdef HAVE_BZLIB_H
	return BZ2_bzlibVersion();
#else
	return NULL;
#endif
}
Example #6
0
AboutDialog::AboutDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::AboutDialog)
{
    ui->setupUi(this);
    QString text = QString("<h1>%1</h1>QT v.%2<br>bzlib v.%3")
            .arg(CommonData::getInstance()->getAppId())
            .arg(qVersion())
            .arg(BZ2_bzlibVersion());
    this->ui->text->setText(text);
}
Example #7
0
rc_t call_bz2( void )
{
    const char * bz2_vers = NULL;

    bz2_vers = BZ2_bzlibVersion();
    if ( bz2_vers == NULL )
        return RC( rcExe, rcCondition, rcValidating, rcInterface, rcInvalid );
    OUTMSG (( "bz2 version is : '%s'\n", bz2_vers ));

    return 0;
}
Example #8
0
int camlzip_bzlibversion(void)
{
  CAMLparam0 ();
  CAMLlocal1 (v);
#ifdef HAVE_BZLIBVERSION
  v = copy_string (BZ2_bzlibVersion());
  CAMLreturn (v);
#else
  failwith("bzlibVersion not found");
#endif
}
Example #9
0
void BZ2_bz__AssertH__fail ( int errcode )
{
   fprintf(stderr,
      "\n\nbzip2/libbzip2: internal error number %d.\n"
      "This is a bug in bzip2/libbzip2, %s.\n"
      "Please report it to me at: [email protected].  If this happened\n"
      "when you were using some program which uses libbzip2 as a\n"
      "component, you should also report this bug to the author(s)\n"
      "of that program.  Please make an effort to report this bug;\n"
      "timely and accurate bug reports eventually lead to higher\n"
      "quality software.  Thanks.  Julian Seward, 21 March 2000.\n\n",
      errcode,
      BZ2_bzlibVersion()
   );
   exit(3);
}
Example #10
0
int register_bzip2(char **version, char **date)
{
#ifdef HAVE_BZ2_LIB
  char *libver, *versionp, *datep, *sep;

  H5Z_class_t filter_class = {
    H5Z_CLASS_T_VERS,             /* H5Z_class_t version */
    (H5Z_filter_t)(FILTER_BZIP2), /* filter_id */
    1, 1,                         /* Encoding and decoding enabled */
    "bzip2",                      /* comment */
    NULL,                         /* can_apply_func */
    NULL,                         /* set_local_func */
    (H5Z_func_t)(bzip2_deflate)   /* filter_func */
  };

  /* Register the filter class for the bzip2 compressor. */
  H5Zregister(&filter_class);

  /* Get the library major version from the version string. */
  libver = strdup(BZ2_bzlibVersion());
  sep = strchr(libver, ',');
  assert(sep != NULL);
  assert(*(sep + 1) == ' ');
  *sep = '\0';
  versionp = libver;
  datep = sep + 2;  /* after the comma and a space */

  *version = strdup(versionp);
  *date = strdup(datep);

  free(libver);
  return 1;  /* library is available */

#else
  return 0;  /* library is not available */
#endif  /* defined HAVE_BZ2_LIB */

}
Example #11
0
int main(int argc,char *argv[])
{
   int decompress = 0;
   int level = 9;
   char *fn_r = NULL;
   char *fn_w = NULL;

#ifdef _WIN32
   if(BZ2DLLLoadLibrary()<0){
      fprintf(stderr,"Loading of %s failed.  Giving up.\n", BZ2_LIBNAME);
      exit(1);
   }
   printf("Loading of %s succeeded.  Library version is %s.\n",
          BZ2_LIBNAME, BZ2_bzlibVersion() );
#endif
   while(++argv,--argc){
      if(**argv =='-' || **argv=='/'){
         char *p;

         for(p=*argv+1;*p;p++){
            if(*p=='d'){
               decompress = 1;
            }else if('1'<=*p && *p<='9'){
               level = *p - '0';
            }else{
               usage();
               exit(1);
            }
         }
      }else{
         break;
      }
   }
   if(argc>=1){
      fn_r = *argv;
      argc--;argv++;
   }else{
      fn_r = NULL;
   }
   if(argc>=1){
      fn_w = *argv;
      argc--;argv++;
   }else{
      fn_w = NULL;
   }
   {
      int len;
      char buff[0x1000];
      char mode[10];

      if(decompress){
         BZFILE *BZ2fp_r = NULL;
         FILE *fp_w = NULL;

         if(fn_w){
            if((fp_w = fopen(fn_w,"wb"))==NULL){
               printf("can't open [%s]\n",fn_w);
               perror("reason:");
               exit(1);
            }
         }else{
            fp_w = stdout;
         }
         if((fn_r == NULL && (BZ2fp_r = BZ2_bzdopen(fileno(stdin),"rb"))==NULL)
            || (fn_r != NULL && (BZ2fp_r = BZ2_bzopen(fn_r,"rb"))==NULL)){
            printf("can't bz2openstream\n");
            exit(1);
         }
         while((len=BZ2_bzread(BZ2fp_r,buff,0x1000))>0){
            fwrite(buff,1,len,fp_w);
         }
         BZ2_bzclose(BZ2fp_r);
         if(fp_w != stdout) fclose(fp_w);
      }else{
         BZFILE *BZ2fp_w = NULL;
         FILE *fp_r = NULL;

         if(fn_r){
            if((fp_r = fopen(fn_r,"rb"))==NULL){
               printf("can't open [%s]\n",fn_r);
               perror("reason:");
               exit(1);
            }
         }else{
            fp_r = stdin;
         }
         mode[0]='w';
         mode[1] = '0' + level;
         mode[2] = '\0';

         if((fn_w == NULL && (BZ2fp_w = BZ2_bzdopen(fileno(stdout),mode))==NULL)
            || (fn_w !=NULL && (BZ2fp_w = BZ2_bzopen(fn_w,mode))==NULL)){
            printf("can't bz2openstream\n");
            exit(1);
         }
         while((len=fread(buff,1,0x1000,fp_r))>0){
            BZ2_bzwrite(BZ2fp_w,buff,len);
         }
         BZ2_bzclose(BZ2fp_w);
         if(fp_r!=stdin)fclose(fp_r);
      }
   }
#ifdef _WIN32
   BZ2DLLFreeLibrary();
#endif
   return 0;
}
Example #12
0
bool XzeroDaemon::setup(std::istream *settings, const std::string& filename, int optimizationLevel)
{
    TRACE("setup(%s)", filename.c_str());

    runner_->setErrorHandler(std::bind(&wrap_log_error, this, "parser", std::placeholders::_1));
    runner_->setOptimizationLevel(optimizationLevel);

    if (!runner_->open(filename, settings)) {
        sd_notifyf(0, "ERRNO=%d", errno);
        goto err;
    }

    if (!validateConfig())
        goto err;

    // run setup
    TRACE("run 'setup'");
    if (runner_->invoke(runner_->findHandler("setup")))
        goto err;

    // grap the request handler
    TRACE("get pointer to 'main'");

    {
        bool (*main)(void*);
        main = runner_->getPointerTo(runner_->findHandler("main"));

        if (!main)
            goto err;

        server_->requestHandler = main;
    }

    // {{{ setup server-tag
    {
#if defined(HAVE_SYS_UTSNAME_H)
        {
            utsname utsname;
            if (uname(&utsname) == 0) {
                addComponent(std::string(utsname.sysname) + "/" + utsname.release);
                addComponent(utsname.machine);
            }
        }
#endif

#if defined(HAVE_BZLIB_H)
        {
            std::string zver("bzip2/");
            zver += BZ2_bzlibVersion();
            zver = zver.substr(0, zver.find(","));
            addComponent(zver);
        }
#endif

#if defined(HAVE_ZLIB_H)
        {
            std::string zver("zlib/");
            zver += zlib_version;
            addComponent(zver);
        }
#endif

        Buffer tagbuf;
        tagbuf.push_back("x0/" VERSION);

        if (!components_.empty())
        {
            tagbuf.push_back(" (");

            for (int i = 0, e = components_.size(); i != e; ++i)
            {
                if (i)
                    tagbuf.push_back(", ");

                tagbuf.push_back(components_[i]);
            }

            tagbuf.push_back(")");
        }
        server_->tag = tagbuf.str();
    }
    // }}}

    // {{{ run post-config hooks
    TRACE("setup: post_config");
    for (auto i: plugins_)
        if (!i->post_config())
            goto err;
    // }}}

    // {{{ run post-check hooks
    TRACE("setup: post_check");
    for (auto i: plugins_)
        if (!i->post_check())
            goto err;
    // }}}

    // {{{ check for available TCP listeners
    if (server_->listeners().empty()) {
        log(Severity::error, "No HTTP listeners defined");
        goto err;
    }
    for (auto i: server_->listeners())
        if (!i->isOpen())
            goto err;
    // }}}

    // {{{ check for SO_REUSEPORT feature in TCP listeners
    if (server_->workers().size() == 1) {
        // fast-path scheduling for single-threaded mode
        server_->workers().front()->bind(server_->listeners().front());
    } else {
        std::list<ServerSocket*> dups;
        for (auto listener: server_->listeners()) {
            if (listener->reusePort()) {
                for (auto worker: server_->workers()) {
                    if (worker->id() > 0) {
                        // clone listener for non-main worker
                        listener = listener->clone(worker->loop());
                        dups.push_back(listener);
                    }
                    worker->bind(listener);
                }
            }
        }

        // FIXME: this is not yet well thought.
        // - how to handle configuration file reloads wrt SO_REUSEPORT?
        for (auto dup: dups) {
            server_->listeners().push_back(dup);
        }
    }
    // }}}

    // {{{ x0d: check for superfluous passed file descriptors (and close them)
    for (auto fd: ServerSocket::getInheritedSocketList()) {
        bool found = false;
        for (auto li: server_->listeners()) {
            if (fd == li->handle()) {
                found = true;
                break;
            }
        }
        if (!found) {
            log(Severity::debug, "Closing inherited superfluous listening socket %d.", fd);
            ::close(fd);
        }
    }
    // }}}

    // {{{ systemd: check for superfluous passed file descriptors
    if (int count = sd_listen_fds(0)) {
        int maxfd = SD_LISTEN_FDS_START + count;
        count = 0;
        for (int fd = SD_LISTEN_FDS_START; fd < maxfd; ++fd) {
            bool found = false;
            for (auto li: server_->listeners()) {
                if (fd == li->handle()) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                ++count;
            }
        }
        if (count) {
            fprintf(stderr, "superfluous systemd file descriptors: %d\n", count);
            return false;
        }
    }
    // }}}

    // XXX post worker wakeup
    // we do an explicit wakeup of all workers here since there might be already
    // some (configure-time related) events pending, i.e. director's (fcgi) health checker
    // FIXME this is more a workaround than a fix.
    for (auto worker: server_->workers())
        worker->wakeup();

    TRACE("setup: done.");
    return true;

err:
    return false;
}
Example #13
0
bool XzeroDaemon::setup(std::unique_ptr<std::istream>&& settings, const std::string& filename, int optimizationLevel)
{
	TRACE(1, "setup(%s)", filename.c_str());

    FlowParser parser(this);
    parser.importHandler = std::bind(&XzeroDaemon::import, this, std::placeholders::_1, std::placeholders::_2,
            std::placeholders::_3);

    if (!parser.open(filename, std::move(settings))) {
        sd_notifyf(0, "ERRNO=%d", errno);
        fprintf(stderr, "Failed to open file: %s\n", filename.c_str());
        return false;
    }

	unit_ = parser.parse();
    if (!unit_)
        return false;

    if (dumpAST_)
        ASTPrinter::print(unit_.get());

    std::unique_ptr<IRProgram> ir = IRGenerator::generate(unit_.get());
    if (!ir) {
        fprintf(stderr, "IR generation failed. Aborting.\n");
        return false;
    }

    {
        PassManager pm;

        // mandatory passes
        pm.registerPass(std::make_unique<UnusedBlockPass>());

        // optional passes
        if (optimizationLevel >= 1) {
            pm.registerPass(std::make_unique<EmptyBlockElimination>());
            pm.registerPass(std::make_unique<InstructionElimination>());
        }

        pm.run(ir.get());
    }

    if (dumpIR_) {
        ir->dump();
    }

    program_ = TargetCodeGenerator().generate(ir.get());

    ir.reset();

    if (!program_) {
        fprintf(stderr, "Code generation failed. Aborting.\n");
        return false;
    }

    if (!program_->link(this)) {
        fprintf(stderr, "Program linking failed. Aborting.\n");
        return false;
    }

	if (!validateConfig()) {
		return false;
    }

    if (dumpTargetCode_)
        program_->dump();

	// run setup
	TRACE(1, "run 'setup'");
    if (program_->findHandler("setup")->run(nullptr))
        // should not return true
        return false;

	// grap the request handler
	TRACE(1, "get pointer to 'main'");

    {
        auto main = program_->findHandler("main");

        server_->requestHandler = [=](x0::HttpRequest* r) {
            FlowVM::Runner* cx = static_cast<FlowVM::Runner*>(r->setCustomData(r, main->createRunner()));
            cx->setUserData(r);
            bool handled = cx->run();
            if (!cx->isSuspended() && !handled) {
                r->finish();
            }
        };
    }

	// {{{ setup server-tag
	{
#if defined(HAVE_SYS_UTSNAME_H)
		{
			utsname utsname;
			if (uname(&utsname) == 0) {
				addComponent(std::string(utsname.sysname) + "/" + utsname.release);
				addComponent(utsname.machine);
			}
		}
#endif

#if defined(HAVE_BZLIB_H)
		{
			std::string zver("bzip2/");
			zver += BZ2_bzlibVersion();
			zver = zver.substr(0, zver.find(","));
			addComponent(zver);
		}
#endif

#if defined(HAVE_ZLIB_H)
		{
			std::string zver("zlib/");
			zver += zlib_version;
			addComponent(zver);
		}
#endif

		Buffer tagbuf;
		tagbuf.push_back("x0/" VERSION);

		if (!components_.empty())
		{
			tagbuf.push_back(" (");

			for (int i = 0, e = components_.size(); i != e; ++i)
			{
				if (i)
					tagbuf.push_back(", ");

				tagbuf.push_back(components_[i]);
			}

			tagbuf.push_back(")");
		}
		server_->tag = tagbuf.str();
	}
	// }}}

	// {{{ run post-config hooks
	TRACE(1, "setup: post_config");
	for (auto i: plugins_)
		if (!i->post_config())
			goto err;
	// }}}

	// {{{ run post-check hooks
	TRACE(1, "setup: post_check");
	for (auto i: plugins_)
		if (!i->post_check())
			goto err;
	// }}}

	// {{{ check for available TCP listeners
	if (server_->listeners().empty()) {
		log(Severity::error, "No HTTP listeners defined");
		goto err;
	}
	for (auto i: server_->listeners())
		if (!i->isOpen())
			goto err;
	// }}}

	// {{{ check for SO_REUSEPORT feature in TCP listeners
	if (server_->workers().size() == 1) {
		// fast-path scheduling for single-threaded mode
		server_->workers().front()->bind(server_->listeners().front());
	} else {
		std::list<ServerSocket*> dups;
		for (auto listener: server_->listeners()) {
			if (listener->reusePort()) {
				for (auto worker: server_->workers()) {
					if (worker->id() > 0) {
						// clone listener for non-main worker
						listener = listener->clone(worker->loop());
						dups.push_back(listener);
					}
					worker->bind(listener);
				}
			}
		}

		// FIXME: this is not yet well thought.
		// - how to handle configuration file reloads wrt SO_REUSEPORT?
		for (auto dup: dups) {
			server_->listeners().push_back(dup);
		}
	}
	// }}}

	// {{{ x0d: check for superfluous passed file descriptors (and close them)
	for (auto fd: ServerSocket::getInheritedSocketList()) {
		bool found = false;
		for (auto li: server_->listeners()) {
			if (fd == li->handle()) {
				found = true;
				break;
			}
		}
		if (!found) {
			log(Severity::debug, "Closing inherited superfluous listening socket %d.", fd);
			::close(fd);
		}
	}
	// }}}

	// {{{ systemd: check for superfluous passed file descriptors
	if (int count = sd_listen_fds(0)) {
		int maxfd = SD_LISTEN_FDS_START + count;
		count = 0;
		for (int fd = SD_LISTEN_FDS_START; fd < maxfd; ++fd) {
			bool found = false;
			for (auto li: server_->listeners()) {
				if (fd == li->handle()) {
					found = true;
					break;
				}
			}
			if (!found) {
				++count;
			}
		}
		if (count) {
			fprintf(stderr, "superfluous systemd file descriptors: %d\n", count);
			return false;
		}
	}
	// }}}

	// XXX post worker wakeup
	// we do an explicit wakeup of all workers here since there might be already
	// some (configure-time related) events pending, i.e. director's (fcgi) health checker
	// FIXME this is more a workaround than a fix.
	for (auto worker: server_->workers())
		worker->wakeup();

	TRACE(1, "setup: done.");
	return true;

err:
	return false;
}