Esempio n. 1
0
bool
FirebirdDriver::initialize()
{
    if (_library != NULL)
	return true;

    FirebirdConfig config;
    if (!config.load())
	return error("Can't read firebird.cfg file");

    // Set firebird install directory
#ifdef WIN32
    SetEnvironmentVariable("INTERBASE", parseDir(config.installDir));
    SetEnvironmentVariable("FIREBIRD", parseDir(config.installDir));
#else
    setenv("INTERBASE", parseDir(config.installDir), true);
    setenv("FIREBIRD", parseDir(config.installDir), true);
#endif

    // Try to load the library
    QLibrary* library = new QLibrary(config.library);
    if (!library->load()) {
	libraryError();
	delete library;
	return error("Can't load firebird library: " + config.library);
    }

    _library = library;
    _procs = new FirebirdProcs(_library);

    return true;
}
Esempio n. 2
0
int
main(int ac, const char** av)
{
  const unsigned PropHeaderSize = 5;
  const unsigned HeaderSize = 13;

  SizeT inSize = SYMBOL(end) - SYMBOL(start);

  int32_t outSize32 = read4(SYMBOL(start) + PropHeaderSize);
  SizeT outSize = outSize32;

  uint8_t* out = static_cast<uint8_t*>(malloc(outSize));
  if (out) {
    ISzAlloc allocator = { myAllocate, myFree };
    ELzmaStatus status = LZMA_STATUS_NOT_SPECIFIED;

    if (SZ_OK == LzmaDecode
        (out, &outSize, SYMBOL(start) + HeaderSize, &inSize, SYMBOL(start),
         PropHeaderSize, LZMA_FINISH_END, &status, &allocator))
    {
      const unsigned BufferSize = 1024;
      char buffer[BufferSize];
      const char* name = temporaryFileName(buffer, BufferSize);
      if (name) {
        int file = open(name, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, S_IRWXU);
        if (file != -1) {
          SizeT result = write(file, out, outSize);
          free(out);

          if (close(file) == 0 and outSize == result) {
            void* library = openLibrary(name);
            unlink(name);

            if (library) {
              void* main = librarySymbol(library, "avianMain");
              if (main) {
                int (*mainFunction)(const char*, int, const char**);
                memcpy(&mainFunction, &main, sizeof(void*));
                return mainFunction(name, ac, av);
              } else {
                fprintf(stderr, "unable to find main in %s", name);
              }
            } else {
              fprintf(stderr, "unable to load %s: %s\n", name,
                      libraryError(library));
            }
          } else {
            unlink(name);

            fprintf(stderr, "close or write failed; tried %d, got %d; %s\n",
                    static_cast<int>(outSize), static_cast<int>(result),
                    strerror(errno));
          }
        } else {
          fprintf(stderr, "unable to open %s\n", name);
        }
      } else {
        fprintf(stderr, "unable to make temporary file name\n");
      }
    } else {
      fprintf(stderr, "unable to decode LZMA data\n");
    }
  } else {
    fprintf(stderr, "unable to allocate buffer of size %d\n",
            static_cast<int>(outSize));
  }

  return -1;
}
Esempio n. 3
0
    void Kernel::launchInitPhase(void)
    {
        LibraryHandle handle = loadLibrary(m_initFilename);

        if( ! handle )
            throw std::system_error(EACCES, std::system_category(), m_initFilename + m_moduleExtension + ", " + libraryError() );


        IKernel::InitFunction fct = (IKernel::InitFunction) searchSymbol(handle, "init");

        if( ! fct )
            throw std::system_error(ENOEXEC, std::system_category(), m_initFilename + m_moduleExtension + ", " + libraryError() );
        fct( *this);

        closeLibrary(handle);
    }