Exemplo n.º 1
0
char* TRI_StringInt32 (int32_t attr) {
  char buffer[12];
  char* p;

  if (attr == INT32_MIN) {
    return TRI_DuplicateString("-2147483648");
  }

  p = buffer;

  if (attr < 0) {
    *p++ = '-';
    attr = -attr;
  }

  if (1000000000L <= attr) { *p++ = (char)((attr / 1000000000L) % 10 + '0'); }
  if ( 100000000L <= attr) { *p++ = (char)((attr /  100000000L) % 10 + '0'); }
  if (  10000000L <= attr) { *p++ = (char)((attr /   10000000L) % 10 + '0'); }
  if (   1000000L <= attr) { *p++ = (char)((attr /    1000000L) % 10 + '0'); }
  if (    100000L <= attr) { *p++ = (char)((attr /     100000L) % 10 + '0'); }
  if (     10000L <= attr) { *p++ = (char)((attr /      10000L) % 10 + '0'); }
  if (      1000L <= attr) { *p++ = (char)((attr /       1000L) % 10 + '0'); }
  if (       100L <= attr) { *p++ = (char)((attr /        100L) % 10 + '0'); }
  if (        10L <= attr) { *p++ = (char)((attr /         10L) % 10 + '0'); }

  *p++ = (char)(attr % 10 + '0');
  *p = '\0';

  return TRI_DuplicateString(buffer);
}
Exemplo n.º 2
0
bool TRI_StartThread (TRI_thread_t* thread,
                      TRI_tid_t* threadId,
                      char const* name,
                      void (*starter)(void*),
                      void* data) {
  thread_data_t* d = static_cast<thread_data_t*>(TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(thread_data_t), false));

  d->starter = starter;
  d->_data = data;
  d->_name = TRI_DuplicateString(name);

  int rc = pthread_create(thread, 0, &ThreadStarter, d);

  if (rc != 0) {
    TRI_set_errno(TRI_ERROR_SYS_ERROR);
    LOG_ERROR("could not start thread: %s", strerror(errno));

    TRI_Free(TRI_CORE_MEM_ZONE, d);
    return false;
  }

  if (threadId != nullptr) {
    *threadId = (TRI_tid_t) *thread;
  }

  return true;
}
Exemplo n.º 3
0
bool TRI_StartThread (TRI_thread_t* thread,  const char* name, void (*starter)(void*), void* data) {
  DWORD threadId;
  thread_data_t* d;

  d = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(thread_data_t), false);

  d->starter = starter;
  d->_data = data;
  d->_name = TRI_DuplicateString(name);

  *thread = CreateThread(0, // default security attributes
                         0, // use default stack size
                         ThreadStarter, // thread function name
                         d, // argument to thread function
                         0, // use default creation flags
                         &threadId); // returns the thread identifier

  if (*thread == 0) {
    TRI_Free(TRI_CORE_MEM_ZONE, d);
    LOG_ERROR("could not start thread: %s ", strerror(errno));
    return false;
  }

  return true;
}
Exemplo n.º 4
0
TRI_select_datapart_t* TRI_CreateDataPart(const char* alias, 
                                          const TRI_doc_collection_t* collection,
                                          const TRI_select_part_e type,
                                          const size_t extraDataSize) {
  TRI_select_datapart_t* datapart;
  
  if (extraDataSize) {
    assert(!collection);
  }
  if (collection) {
    assert(extraDataSize == 0);
  }

  datapart = (TRI_select_datapart_t*) TRI_Allocate(sizeof(TRI_select_datapart_t));
  if (!datapart) {
    return NULL;
  }

  datapart->_alias         = TRI_DuplicateString(alias);
  datapart->_collection    = (TRI_doc_collection_t*) collection;
  datapart->_type          = type;
  datapart->_extraDataSize = extraDataSize;

  datapart->free           = FreeDataPart;

  return datapart;
}
Exemplo n.º 5
0
static TRI_aql_bind_parameter_t* CreateParameter (const char* const name,
                                                  const TRI_json_t* const value) {
  TRI_aql_bind_parameter_t* parameter;

  assert(name);
  assert(value);

  parameter = (TRI_aql_bind_parameter_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_aql_bind_parameter_t), false);
  if (!parameter) {
    return NULL;
  }

  parameter->_name = TRI_DuplicateString(name);
  if (!parameter->_name) {
    TRI_Free(TRI_UNKNOWN_MEM_ZONE, parameter);
    return NULL;
  }

  parameter->_value = TRI_CopyJson(TRI_UNKNOWN_MEM_ZONE, (TRI_json_t*) value);
  if (!parameter->_value) {
    TRI_Free(TRI_UNKNOWN_MEM_ZONE, parameter->_name);
    TRI_Free(TRI_UNKNOWN_MEM_ZONE, parameter);
    return NULL;
  }

  return parameter;
}
Exemplo n.º 6
0
char* TRI_StringUInt64 (uint64_t attr) {
  char buffer[21];
  char* p = buffer;

  if (10000000000000000000ULL <= attr) { *p++ = (char)((attr / 10000000000000000000ULL) % 10 + '0'); }
  if ( 1000000000000000000ULL <= attr) { *p++ = (char)((attr /  1000000000000000000ULL) % 10 + '0'); }
  if (  100000000000000000ULL <= attr) { *p++ = (char)((attr /   100000000000000000ULL) % 10 + '0'); }
  if (   10000000000000000ULL <= attr) { *p++ = (char)((attr /    10000000000000000ULL) % 10 + '0'); }
  if (    1000000000000000ULL <= attr) { *p++ = (char)((attr /     1000000000000000ULL) % 10 + '0'); }
  if (     100000000000000ULL <= attr) { *p++ = (char)((attr /      100000000000000ULL) % 10 + '0'); }
  if (      10000000000000ULL <= attr) { *p++ = (char)((attr /       10000000000000ULL) % 10 + '0'); }
  if (       1000000000000ULL <= attr) { *p++ = (char)((attr /        1000000000000ULL) % 10 + '0'); }
  if (        100000000000ULL <= attr) { *p++ = (char)((attr /         100000000000ULL) % 10 + '0'); }
  if (         10000000000ULL <= attr) { *p++ = (char)((attr /          10000000000ULL) % 10 + '0'); }
  if (          1000000000ULL <= attr) { *p++ = (char)((attr /           1000000000ULL) % 10 + '0'); }
  if (           100000000ULL <= attr) { *p++ = (char)((attr /            100000000ULL) % 10 + '0'); }
  if (            10000000ULL <= attr) { *p++ = (char)((attr /             10000000ULL) % 10 + '0'); }
  if (             1000000ULL <= attr) { *p++ = (char)((attr /              1000000ULL) % 10 + '0'); }
  if (              100000ULL <= attr) { *p++ = (char)((attr /               100000ULL) % 10 + '0'); }
  if (               10000ULL <= attr) { *p++ = (char)((attr /                10000ULL) % 10 + '0'); }
  if (                1000ULL <= attr) { *p++ = (char)((attr /                 1000ULL) % 10 + '0'); }
  if (                 100ULL <= attr) { *p++ = (char)((attr /                  100ULL) % 10 + '0'); }
  if (                  10ULL <= attr) { *p++ = (char)((attr /                   10ULL) % 10 + '0'); }

  *p++ = (char)(attr % 10 + '0');
  *p = '\0';

  return TRI_DuplicateString(buffer);
}
Exemplo n.º 7
0
char* TRI_ParseQueryAllocString (TRI_query_template_t* const template_, 
                                 const char* string) {
  // do string duplication
  char* copy = TRI_DuplicateString(string);

  // store pointer to copy
  return TRI_ParseQueryRegisterString(template_, copy);
}
Exemplo n.º 8
0
bool TRI_RegisterMimetype (const char* extension,
                           const char* mimetype,
                           bool appendCharset) {
  mimetype_t* entry = static_cast<mimetype_t*>(TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(mimetype_t), false));
  entry->_extension = TRI_DuplicateString(extension);
  entry->_appendCharset = appendCharset;

  if (appendCharset) {
    entry->_mimetype = TRI_Concatenate2String(mimetype, "; charset=utf-8");
  }
  else {
    entry->_mimetype = TRI_DuplicateString(mimetype);
  }

  void* found = TRI_InsertKeyAssociativePointer(&Mimetypes, extension, entry, false);

  return (found != nullptr);
}
Exemplo n.º 9
0
void TRI_CreateExternalProcess (const char* executable,
                                const char** arguments,
                                size_t n,
                                bool usePipes,
                                TRI_external_id_t* pid) {

  // create the external structure
  TRI_external_t* external = static_cast<TRI_external_t*>(TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_external_t), true));

  external->_executable = TRI_DuplicateString(executable);
  external->_numberArguments = n + 1;

  external->_arguments = static_cast<char**>(TRI_Allocate(TRI_CORE_MEM_ZONE, (n + 2) * sizeof(char*), true));
  external->_arguments[0] = TRI_DuplicateString(executable);

  for (size_t i = 0;  i < n;  ++i) {
    external->_arguments[i + 1] = TRI_DuplicateString(arguments[i]);
  }

  external->_arguments[n + 1] = nullptr;
  external->_status = TRI_EXT_NOT_STARTED;

  StartExternalProcess(external, usePipes);
  if (external->_status != TRI_EXT_RUNNING) {
    pid->_pid = TRI_INVALID_PROCESS_ID;
    FreeExternal(external);
    return;
  }

  LOG_DEBUG("adding process %d to list", (int) external->_pid);
  TRI_LockMutex(&ExternalProcessesLock);
  TRI_PushBackVectorPointer(&ExternalProcesses, external);
  // Note that the following deals with different types under windows,
  // however, this code here can be written in a platform-independent
  // way:
  pid->_pid = external->_pid;
  pid->_readPipe = external->_readPipe;
  pid->_writePipe = external->_writePipe;
  TRI_UnlockMutex(&ExternalProcessesLock);
}
Exemplo n.º 10
0
void TRI_InitializeProcess (int argc, char* argv[]) {
  TRI_PhysicalMemory = GetPhysicalMemory();

  if (ProcessName != nullptr) {
    return;
  }

  ProcessName = TRI_DuplicateString(argv[0]);
  ARGC = argc;
  ARGV = argv;

  TRI_InitVectorPointer(&ExternalProcesses, TRI_CORE_MEM_ZONE);
  TRI_InitMutex(&ExternalProcessesLock);
}
Exemplo n.º 11
0
char* TRI_StringInt64 (int64_t attr) {
  char buffer[21];
  char* p = buffer;

  if (attr == INT64_MIN) {
    return TRI_DuplicateString("-9223372036854775808");
  }

  if (attr < 0) {
    *p++ = '-';
    attr = -attr;
  }

  if (1000000000000000000LL <= attr) { *p++ = (char)((attr / 1000000000000000000LL) % 10 + '0'); }
  if ( 100000000000000000LL <= attr) { *p++ = (char)((attr /  100000000000000000LL) % 10 + '0'); }
  if (  10000000000000000LL <= attr) { *p++ = (char)((attr /   10000000000000000LL) % 10 + '0'); }
  if (   1000000000000000LL <= attr) { *p++ = (char)((attr /    1000000000000000LL) % 10 + '0'); }
  if (    100000000000000LL <= attr) { *p++ = (char)((attr /     100000000000000LL) % 10 + '0'); }
  if (     10000000000000LL <= attr) { *p++ = (char)((attr /      10000000000000LL) % 10 + '0'); }
  if (      1000000000000LL <= attr) { *p++ = (char)((attr /       1000000000000LL) % 10 + '0'); }
  if (       100000000000LL <= attr) { *p++ = (char)((attr /        100000000000LL) % 10 + '0'); }
  if (        10000000000LL <= attr) { *p++ = (char)((attr /         10000000000LL) % 10 + '0'); }
  if (         1000000000LL <= attr) { *p++ = (char)((attr /          1000000000LL) % 10 + '0'); }
  if (          100000000LL <= attr) { *p++ = (char)((attr /           100000000LL) % 10 + '0'); }
  if (           10000000LL <= attr) { *p++ = (char)((attr /            10000000LL) % 10 + '0'); }
  if (            1000000LL <= attr) { *p++ = (char)((attr /             1000000LL) % 10 + '0'); }
  if (             100000LL <= attr) { *p++ = (char)((attr /              100000LL) % 10 + '0'); }
  if (              10000LL <= attr) { *p++ = (char)((attr /               10000LL) % 10 + '0'); }
  if (               1000LL <= attr) { *p++ = (char)((attr /                1000LL) % 10 + '0'); }
  if (                100LL <= attr) { *p++ = (char)((attr /                 100LL) % 10 + '0'); }
  if (                 10LL <= attr) { *p++ = (char)((attr /                  10LL) % 10 + '0'); }

  *p++ = (char)(attr % 10 + '0');
  *p = '\0';

  return TRI_DuplicateString(buffer);
}
Exemplo n.º 12
0
bool TRI_RegisterFunctionAql (TRI_associative_pointer_t* functions,
                              const char* const externalName, 
                              const char* const internalName, 
                              const bool isDeterministic,
                              const bool isGroup,
                              const char* const argPattern) {
  TRI_aql_function_t* function;
  
  function = (TRI_aql_function_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_aql_function_t), false);

  if (!function) {
    return false;
  }

  function->_externalName = TRI_DuplicateString(externalName);
  if (!function->_externalName) {
    TRI_Free(TRI_UNKNOWN_MEM_ZONE, function);
    return false;
  }

  // normalize name by upper-casing it
  function->_internalName = TRI_UpperAsciiString(internalName);
  if (!function->_internalName) {
    TRI_Free(TRI_UNKNOWN_MEM_ZONE, function->_externalName);
    TRI_Free(TRI_UNKNOWN_MEM_ZONE, function);
    return false;
  }

  if (TRI_InsertKeyAssociativePointer(functions, externalName, function, false)) {
    // function already registered
    TRI_Free(TRI_UNKNOWN_MEM_ZONE, function->_externalName);
    TRI_Free(TRI_UNKNOWN_MEM_ZONE, function->_internalName);
    TRI_Free(TRI_UNKNOWN_MEM_ZONE, function);
    return false;
  }

  function->_isDeterministic = isDeterministic; 
  function->_isGroup = isGroup; 
  function->_argPattern = argPattern;

  // set minArgs and maxArgs
  SetArgumentCount(function);

  return true;
}
Exemplo n.º 13
0
static int RemoveCompactor (TRI_document_collection_t* document,
                            TRI_datafile_t* compactor) {
  TRI_primary_collection_t* primary;
  size_t i;

  primary = &document->base;

  LOG_TRACE("removing empty compaction file '%s'", compactor->getName(compactor));
  
  // remove the datafile from the list of datafiles
  TRI_WRITE_LOCK_DATAFILES_DOC_COLLECTION(primary);

  // remove the compactor from the list of compactors
  if (! LocateDatafile(&primary->base._compactors, compactor->_fid, &i)) {
    TRI_WRITE_UNLOCK_DATAFILES_DOC_COLLECTION(primary);
    
    LOG_ERROR("logic error: could not locate compactor");

    return TRI_ERROR_INTERNAL;
  }
    
  TRI_RemoveVectorPointer(&primary->base._compactors, i);

  TRI_WRITE_UNLOCK_DATAFILES_DOC_COLLECTION(primary);


  // close the file & remove it
  if (compactor->isPhysical(compactor)) {
    char* filename;

    filename = TRI_DuplicateString(compactor->getName(compactor));
    TRI_CloseDatafile(compactor);
    TRI_FreeDatafile(compactor);

    TRI_UnlinkFile(filename);
    TRI_Free(TRI_CORE_MEM_ZONE, filename);
  }
  else {
    TRI_CloseDatafile(compactor);
    TRI_FreeDatafile(compactor);
  }

  return TRI_ERROR_NO_ERROR;
}
Exemplo n.º 14
0
char* TRI_GetFunctionCodeQueryJavascript (const TRI_query_node_t* const node,
                                          TRI_associative_pointer_t* bindParameters) {
  TRI_query_javascript_converter_t* js;
  char* function = NULL;
  
  assert(node);
  js = TRI_InitQueryJavascript();

  if (js) {
    TRI_AppendStringStringBuffer(js->_buffer, "(function($) { return ");
    TRI_ConvertQueryJavascript(js, node, bindParameters);
    TRI_AppendStringStringBuffer(js->_buffer, " })");

    function = TRI_DuplicateString(js->_buffer->_buffer);
    TRI_FreeQueryJavascript(js);
  }

  return function;
}
Exemplo n.º 15
0
static TRI_vocbase_col_t* AddCollection (TRI_vocbase_t* vocbase,
                                         TRI_col_type_t type,
                                         char const* name,
                                         TRI_voc_cid_t cid,
                                         char const* path) {
  void const* found;
  TRI_vocbase_col_t* col;

  // create a new proxy
  col = TRI_Allocate(sizeof(TRI_vocbase_col_t));
  col->_vocbase = vocbase;
  col->_type = type;
  TRI_CopyString(col->_name, name, sizeof(col->_name));
  col->_path = (path == NULL ? NULL : TRI_DuplicateString(path));
  col->_collection = NULL;
  col->_newBorn = 0;
  col->_loaded = 0;
  col->_corrupted = 0;
  col->_cid = cid;

  // check name
  found = TRI_InsertKeyAssociativePointer(&vocbase->_collectionsByName, name, col, false);

  if (found != NULL) {
    TRI_Free(col);
    LOG_ERROR("duplicate entry for name '%s'", name);
    return NULL;
  }

  // check collection identifier
  if (cid != 0) {
    found = TRI_InsertKeyAssociativePointer(&vocbase->_collectionsById, &cid, col, false);

    if (found != NULL) {
      TRI_Free(col);
      LOG_ERROR("duplicate entry for identifier '%s'", cid);
      return NULL;
    }
  }

  TRI_PushBackVectorPointer(&vocbase->_collections, col);
  return col;
}
Exemplo n.º 16
0
TRI_aql_variable_t* TRI_CreateVariableAql (const char* const name,
                                           TRI_aql_node_t* const definingNode) { 
  TRI_aql_variable_t* variable;

  variable = (TRI_aql_variable_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_aql_variable_t), false);

  if (variable == NULL) {
    return NULL;
  }

  variable->_name = TRI_DuplicateString(name);

  if (variable->_name == NULL) {
    TRI_FreeVariableAql(variable);
    return NULL;
  }

  variable->_definingNode = definingNode;

  assert(definingNode);

  return variable;
}
Exemplo n.º 17
0
static void RenameDatafileCallback (TRI_datafile_t* datafile,  
                                    void* data) {
  compaction_context_t* context;
  TRI_datafile_t* compactor;
  TRI_primary_collection_t* primary;
  bool ok;
   
  context = data;
  compactor = context->_compactor;
  primary = &context->_document->base;

  ok = false;
  assert(datafile->_fid == compactor->_fid);

  if (datafile->isPhysical(datafile)) {
    char* number;
    char* jname;
    char* tempFilename;
    char* realName;

    realName     = TRI_DuplicateString(datafile->_filename);
    
    // construct a suitable tempname
    number       = TRI_StringUInt64(datafile->_fid);
    jname        = TRI_Concatenate3String("temp-", number, ".db");
    tempFilename = TRI_Concatenate2File(primary->base._directory, jname);

    TRI_FreeString(TRI_CORE_MEM_ZONE, number);
    TRI_FreeString(TRI_CORE_MEM_ZONE, jname);

    if (! TRI_RenameDatafile(datafile, tempFilename)) {
      LOG_ERROR("unable to rename datafile '%s' to '%s'", datafile->getName(datafile), tempFilename);
    }
    else {
      if (! TRI_RenameDatafile(compactor, realName)) {
        LOG_ERROR("unable to rename compaction file '%s' to '%s'", compactor->getName(compactor), realName);
      }
      else {
        ok = true;
      }
    }

    TRI_FreeString(TRI_CORE_MEM_ZONE, tempFilename);
    TRI_FreeString(TRI_CORE_MEM_ZONE, realName);
  }
  else {
    ok = true;
  }

  if (ok) {
    TRI_doc_datafile_info_t* dfi;
    size_t i;
   
    // must acquire a write-lock as we're about to change the datafiles vector 
    TRI_WRITE_LOCK_DATAFILES_DOC_COLLECTION(primary);

    if (! LocateDatafile(&primary->base._datafiles, datafile->_fid, &i)) {
      TRI_WRITE_UNLOCK_DATAFILES_DOC_COLLECTION(primary);

      LOG_ERROR("logic error: could not locate datafile");

      return;
    }

    // put the compactor in place of the datafile
    primary->base._datafiles._buffer[i] = compactor;

    // update dfi
    dfi = TRI_FindDatafileInfoPrimaryCollection(primary, compactor->_fid, false);

    if (dfi != NULL) {
      memcpy(dfi, &context->_dfi, sizeof(TRI_doc_datafile_info_t));
    }
    else {
      LOG_ERROR("logic error: could not find compactor file information");
    }

    if (! LocateDatafile(&primary->base._compactors, compactor->_fid, &i)) {
      TRI_WRITE_UNLOCK_DATAFILES_DOC_COLLECTION(primary);
   
      LOG_ERROR("logic error: could not locate compactor");

      return;
    }

    // remove the compactor from the list of compactors
    TRI_RemoveVectorPointer(&primary->base._compactors, i);
          
    TRI_WRITE_UNLOCK_DATAFILES_DOC_COLLECTION(primary);

    DropDatafileCallback(datafile, primary);
  }

  TRI_Free(TRI_CORE_MEM_ZONE, context);
}
Exemplo n.º 18
0
int TRI_ZipFile (const char* filename, 
                 const char* dir,
                 TRI_vector_string_t const* files,
                 const char* password) {
  void* buffer;
  size_t bufferSize;
  zipFile zf;
#ifdef USEWIN32IOAPI
  zlib_filefunc64_def ffunc;
#endif
  size_t i, n;
  int res;

  if (TRI_ExistsFile(filename)) {
    return TRI_ERROR_CANNOT_OVERWRITE_FILE;
  }

  bufferSize = 16384;
  buffer = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, bufferSize, false);

  if (buffer == NULL) {
    return TRI_ERROR_OUT_OF_MEMORY;
  }

#ifdef USEWIN32IOAPI
  fill_win32_filefunc64A(&ffunc);
  zf = zipOpen2_64(filename, 0, NULL, &ffunc);
#else
  zf = zipOpen64(filename, 0);
#endif

  if (zf == NULL) {
    TRI_Free(TRI_UNKNOWN_MEM_ZONE, buffer);

    return ZIP_ERRNO;
  }

  res = TRI_ERROR_NO_ERROR;

  n = files->_length;
  for (i = 0; i < n; ++i) {
    FILE* fin;
    char* file;
    char* fullfile;
    char* saveName;
    zip_fileinfo zi;
    uint32_t crc;
    int isLarge;

    file = TRI_AtVectorString(files, i);

    if (*dir == '\0') {
      fullfile = TRI_DuplicateString(file);
    }
    else {
      fullfile = TRI_Concatenate2File(dir, file);
    }

    memset(&zi, 0, sizeof(zi));

    res = TRI_Crc32File(fullfile, &crc);

    if (res != TRI_ERROR_NO_ERROR) {
      break;
    }

    isLarge = (TRI_SizeFile(file) > 0xFFFFFFFFLL);
              
    saveName = file;

    while (*saveName == '\\' || *saveName == '/') {
      ++saveName;
    }

    if (zipOpenNewFileInZip3_64(zf,
                                saveName,
                                &zi,
                                NULL,
                                0,
                                NULL,
                                0,
                                NULL, /* comment*/
                                Z_DEFLATED,
                                Z_DEFAULT_COMPRESSION,
                                0,
                                -MAX_WBITS, 
                                DEF_MEM_LEVEL, 
                                Z_DEFAULT_STRATEGY,
                                password,
                                (unsigned long) crc, 
                                isLarge) != ZIP_OK) {
    }

    fin = fopen(fullfile, "rb");
    TRI_FreeString(TRI_CORE_MEM_ZONE, fullfile);

    if (fin == NULL) {
      break;
    }

    while (true) {
      int sizeRead;

      sizeRead = (int) fread(buffer, 1, bufferSize, fin);
      if (sizeRead < bufferSize) {
        if (feof(fin) == 0) {
          res = TRI_set_errno(TRI_ERROR_SYS_ERROR);
          break;
        }
      }

      if (sizeRead > 0) {
        res = zipWriteInFileInZip(zf, buffer, sizeRead);
        if (res != 0) {
          break;
        }
      }
      else if (sizeRead <= 0) {
        break;
      }
    }

    fclose(fin);
    
    zipCloseFileInZip(zf);

    if (res != TRI_ERROR_NO_ERROR) {
      break;
    }
  }

  zipClose(zf, NULL);
  
  TRI_Free(TRI_UNKNOWN_MEM_ZONE, buffer);

  return res;
}