本文整理汇总了C++中TRI_set_errno函数的典型用法代码示例。如果您正苦于以下问题:C++ TRI_set_errno函数的具体用法?C++ TRI_set_errno怎么用?C++ TRI_set_errno使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TRI_set_errno函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TRI_UInt32String
uint32_t TRI_UInt32String (char const* str) {
uint32_t result;
char* endptr;
#if defined(TRI_HAVE_STRTOUL_R)
struct reent buffer;
#elif defined(TRI_HAVE__STRTOUL_R)
struct reent buffer;
#endif
TRI_set_errno(TRI_ERROR_NO_ERROR);
#if defined(TRI_HAVE_STRTOUL_R)
result = strtoul_r(&buffer, str, &endptr, 10);
#elif defined(TRI_HAVE__STRTOUL_R)
result = _strtoul_r(&buffer, str, &endptr, 10);
#else
result = strtoul(str, &endptr, 10);
#endif
while (isspace(*endptr)) {
++endptr;
}
if (*endptr != '\0') {
TRI_set_errno(TRI_ERROR_ILLEGAL_NUMBER);
}
if (errno == ERANGE && (result == 0 || result == UINT32_MAX)) {
TRI_set_errno(TRI_ERROR_NUMERIC_OVERFLOW);
}
return result;
}
示例2: TRI_CreateReplicationApplier
TRI_replication_applier_t* TRI_CreateReplicationApplier (TRI_vocbase_t* vocbase) {
TRI_replication_applier_t* applier;
int res;
applier = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_replication_applier_t), false);
if (applier == NULL) {
return NULL;
}
TRI_InitConfigurationReplicationApplier(&applier->_configuration);
TRI_InitStateReplicationApplier(&applier->_state);
res = LoadConfiguration(vocbase, &applier->_configuration);
if (res != TRI_ERROR_NO_ERROR &&
res != TRI_ERROR_FILE_NOT_FOUND) {
TRI_set_errno(res);
TRI_DestroyStateReplicationApplier(&applier->_state);
TRI_DestroyConfigurationReplicationApplier(&applier->_configuration);
TRI_Free(TRI_CORE_MEM_ZONE, applier);
return NULL;
}
res = TRI_LoadStateReplicationApplier(vocbase, &applier->_state);
if (res != TRI_ERROR_NO_ERROR &&
res != TRI_ERROR_FILE_NOT_FOUND) {
TRI_set_errno(res);
TRI_DestroyStateReplicationApplier(&applier->_state);
TRI_DestroyConfigurationReplicationApplier(&applier->_configuration);
TRI_Free(TRI_CORE_MEM_ZONE, applier);
return NULL;
}
TRI_InitReadWriteLock(&applier->_statusLock);
TRI_InitSpin(&applier->_threadLock);
TRI_InitCondition(&applier->_runStateChangeCondition);
applier->_vocbase = vocbase;
applier->_databaseName = TRI_DuplicateStringZ(TRI_CORE_MEM_ZONE, vocbase->_name);
SetTerminateFlag(applier, false);
assert(applier->_databaseName != NULL);
TRI_SetProgressReplicationApplier(applier, "applier created", false);
return applier;
}
示例3: TRI_GetDirectoryCollection
char* TRI_GetDirectoryCollection (char const* path,
const TRI_col_info_t* const parameter) {
char* filename;
assert(path);
assert(parameter);
// shape collections use just the name, e.g. path/SHAPES
if (parameter->_type == TRI_COL_TYPE_SHAPE) {
filename = TRI_Concatenate2File(path, parameter->_name);
}
// other collections use the collection identifier
else if (TRI_IS_DOCUMENT_COLLECTION(parameter->_type)) {
char* tmp1;
char* tmp2;
tmp1 = TRI_StringUInt64(parameter->_cid);
if (tmp1 == NULL) {
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
return NULL;
}
tmp2 = TRI_Concatenate2String("collection-", tmp1);
if (tmp2 == NULL) {
TRI_FreeString(TRI_CORE_MEM_ZONE, tmp1);
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
return NULL;
}
filename = TRI_Concatenate2File(path, tmp2);
TRI_FreeString(TRI_CORE_MEM_ZONE, tmp1);
TRI_FreeString(TRI_CORE_MEM_ZONE, tmp2);
}
// oops, unknown collection type
else {
TRI_set_errno(TRI_ERROR_ARANGO_UNKNOWN_COLLECTION_TYPE);
return NULL;
}
if (filename == NULL) {
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
}
// might be NULL
return filename;
}
示例4: TRI_StartThread
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;
}
示例5: TRI_AddLinkedArray
int TRI_AddLinkedArray (TRI_linked_array_t* array, void const* data) {
TRI_linked_list_entry_t* entry;
TRI_linked_list_entry_t* found;
// create entry
entry = TRI_Allocate(array->_memoryZone, sizeof(TRI_linked_list_entry_t), false);
if (entry == NULL) {
return TRI_ERROR_OUT_OF_MEMORY;
}
entry->_data = data;
// insert to lookup table
found = TRI_InsertElementAssociativePointer(&array->_array, entry, true);
if (TRI_errno() == TRI_ERROR_OUT_OF_MEMORY) {
TRI_Free(array->_memoryZone, entry);
return TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
}
// this should not happen
if (found != NULL) {
TRI_RemoveLinkedList(&array->_list, found);
TRI_Free(array->_memoryZone, found);
}
// add element at the beginning
TRI_AddLinkedList(&array->_list, entry);
return TRI_ERROR_NO_ERROR;
}
示例6: TRI_ShapeAccessor
TRI_shape_access_t* TRI_ShapeAccessor (TRI_shaper_t* shaper,
TRI_shape_sid_t sid,
TRI_shape_pid_t pid) {
TRI_shape_access_t* accessor;
bool ok;
accessor = TRI_Allocate(shaper->_memoryZone, sizeof(TRI_shape_access_t), false);
if (accessor == NULL) {
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
return NULL;
}
accessor->_sid = sid;
accessor->_pid = pid;
accessor->_code = NULL;
accessor->_memoryZone = shaper->_memoryZone;
ok = BytecodeShapeAccessor(shaper, accessor);
if (ok) {
return accessor;
}
TRI_FreeShapeAccessor(accessor);
return NULL;
}
示例7: TRI_CreateReplicationApplier
TRI_replication_applier_t* TRI_CreateReplicationApplier (TRI_server_t* server,
TRI_vocbase_t* vocbase) {
TRI_replication_applier_t* applier = new TRI_replication_applier_t(server, vocbase);
if (applier == nullptr) {
return nullptr;
}
TRI_InitConfigurationReplicationApplier(&applier->_configuration);
TRI_InitStateReplicationApplier(&applier->_state);
if (vocbase->_type == TRI_VOCBASE_TYPE_NORMAL) {
int res = LoadConfiguration(vocbase, &applier->_configuration);
if (res != TRI_ERROR_NO_ERROR &&
res != TRI_ERROR_FILE_NOT_FOUND) {
TRI_set_errno(res);
TRI_DestroyStateReplicationApplier(&applier->_state);
TRI_DestroyConfigurationReplicationApplier(&applier->_configuration);
delete applier;
return nullptr;
}
res = TRI_LoadStateReplicationApplier(vocbase, &applier->_state);
if (res != TRI_ERROR_NO_ERROR &&
res != TRI_ERROR_FILE_NOT_FOUND) {
TRI_set_errno(res);
TRI_DestroyStateReplicationApplier(&applier->_state);
TRI_DestroyConfigurationReplicationApplier(&applier->_configuration);
delete applier;
return nullptr;
}
}
SetTerminateFlag(applier, false);
TRI_ASSERT(applier->_databaseName != nullptr);
TRI_SetProgressReplicationApplier(applier, "applier created", false);
return applier;
}
示例8: TRI_AllocateZ
void* TRI_AllocateZ (TRI_memory_zone_t* zone, uint64_t n, bool set, char const* file, int line) {
#else
void* TRI_Allocate (TRI_memory_zone_t* zone, uint64_t n, bool set) {
#endif
char* m;
#ifdef TRI_ENABLE_MAINTAINER_MODE
CheckSize(n, file, line);
m = MALLOC_WRAPPER(zone, (size_t) n + sizeof(uintptr_t));
#else
m = MALLOC_WRAPPER(zone, (size_t) n);
#endif
if (m == NULL) {
if (zone->_failable) {
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
return NULL;
}
if (CoreReserve == NULL) {
fprintf(stderr,
"FATAL: failed to allocate %llu bytes for memory zone %d" ZONE_DEBUG_LOCATION ", giving up!\n",
(unsigned long long) n,
(int) zone->_zid
ZONE_DEBUG_PARAMS);
TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL);
}
free(CoreReserve);
CoreReserve = NULL;
fprintf(stderr,
"failed to allocate %llu bytes for memory zone %d" ZONE_DEBUG_LOCATION ", retrying!\n",
(unsigned long long) n,
(int) zone->_zid
ZONE_DEBUG_PARAMS);
#ifdef TRI_ENABLE_MAINTAINER_MODE
return TRI_AllocateZ(zone, n, set, file, line);
#else
return TRI_Allocate(zone, n, set);
#endif
}
#ifdef TRI_ENABLE_MAINTAINER_MODE
else if (set) {
memset(m, 0, (size_t) n + sizeof(uintptr_t));
}
else {
// prefill with 0xA5 (magic value, same as Valgrind will use)
memset(m, 0xA5, (size_t) n + sizeof(uintptr_t));
}
#else
else if (set) {
示例9: TRI_InsertKeyAssociativePointer
void* TRI_InsertKeyAssociativePointer (TRI_associative_pointer_t* array,
void const* key,
void* element,
bool overwrite) {
uint64_t hash;
uint64_t i;
void* old;
// check for out-of-memory
if (array->_nrAlloc == array->_nrUsed) {
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
return NULL;
}
// compute the hash
hash = array->hashKey(array, key);
i = hash % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
// update statistics
array->_nrAdds++;
#endif
// search the table
while (array->_table[i] != NULL && ! array->isEqualKeyElement(array, key, array->_table[i])) {
i = TRI_IncModU64(i, array->_nrAlloc);
#ifdef TRI_INTERNAL_STATS
array->_nrProbesA++;
#endif
}
old = array->_table[i];
// if we found an element, return
if (old != NULL) {
if (overwrite) {
array->_table[i] = element;
}
return old;
}
// add a new element to the associative array
array->_table[i] = element;
array->_nrUsed++;
// if we were adding and the table is more than half full, extend it
if (array->_nrAlloc < 2 * array->_nrUsed) {
ResizeAssociativePointer(array, (uint32_t) (2 * array->_nrAlloc) + 1);
}
return NULL;
}
示例10: slurp
string slurp (string const& filename) {
int fd = TRI_OPEN(filename.c_str(), O_RDONLY);
if (fd == -1) {
TRI_set_errno(errno);
THROW_FILE_OPEN_ERROR("open", filename, "O_RDONLY", errno);
}
char buffer[10240];
StringBuffer result(TRI_CORE_MEM_ZONE);
while (true) {
ssize_t n = TRI_READ(fd, buffer, sizeof(buffer));
if (n == 0) {
break;
}
if (n < 0) {
TRI_set_errno(TRI_ERROR_SYS_ERROR);
LOG_TRACE("read failed for '%s' with %s and result %d on fd %d",
filename.c_str(),
strerror(errno),
(int) n,
fd);
TRI_CLOSE(fd);
THROW_FILE_FUNC_ERROR("read", "", errno);
}
result.appendText(buffer, n);
}
TRI_CLOSE(fd);
string r(result.c_str(), result.length());
return r;
}
示例11: TRI_InsertKeyAssociativeSynced
void* TRI_InsertKeyAssociativeSynced (TRI_associative_synced_t* array,
void const* key,
void* element) {
uint64_t hash;
uint64_t i;
void* old;
// check for out-of-memory
if (array->_nrAlloc == array->_nrUsed) {
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
return NULL;
}
// compute the hash
hash = array->hashKey(array, key);
i = hash % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
// update statistics
array->_nrAdds++;
#endif
// search the table
TRI_WriteLockReadWriteLock(&array->_lock);
while (array->_table[i] != NULL && ! array->isEqualKeyElement(array, key, array->_table[i])) {
i = (i + 1) % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
array->_nrProbesA++;
#endif
}
old = array->_table[i];
// if we found an element, return
if (old != NULL) {
TRI_WriteUnlockReadWriteLock(&array->_lock);
return old;
}
// add a new element to the associative array
array->_table[i] = element;
array->_nrUsed++;
// if we were adding and the table is more than half full, extend it
if (array->_nrAlloc < 2 * array->_nrUsed) {
ResizeAssociativeSynced(array);
}
TRI_WriteUnlockReadWriteLock(&array->_lock);
return NULL;
}
示例12: TRI_AllocateZ
void* TRI_AllocateZ(TRI_memory_zone_t* zone, uint64_t n, bool set,
char const* file, int line) {
#else
void* TRI_Allocate(TRI_memory_zone_t* zone, uint64_t n, bool set) {
#endif
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
CheckSize(n, file, line);
#endif
char* m = static_cast<char*>(MALLOC_WRAPPER(zone, (size_t)n));
if (m == nullptr) {
if (zone->_failable) {
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
return nullptr;
}
if (CoreReserve == nullptr) {
fprintf(stderr,
"FATAL: failed to allocate %llu bytes for core mem zone "
ZONE_DEBUG_LOCATION ", giving up!\n",
(unsigned long long)n ZONE_DEBUG_PARAMS);
TRI_EXIT_FUNCTION(EXIT_FAILURE, nullptr);
}
free(CoreReserve);
CoreReserve = nullptr;
fprintf(
stderr,
"failed to allocate %llu bytes for core mem zone" ZONE_DEBUG_LOCATION
", retrying!\n",
(unsigned long long)n ZONE_DEBUG_PARAMS);
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
return TRI_AllocateZ(zone, n, set, file, line);
#else
return TRI_Allocate(zone, n, set);
#endif
}
if (set) {
memset(m, 0, (size_t)n);
}
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
else {
// prefill with 0xA5 (magic value, same as Valgrind will use)
memset(m, 0xA5, (size_t)n);
}
#endif
return m;
}
示例13: TRI_DoubleString
double TRI_DoubleString (char const* str) {
double result;
char* endptr;
TRI_set_errno(TRI_ERROR_NO_ERROR);
result = strtod(str, &endptr);
while (isspace(*endptr)) {
++endptr;
}
if (*endptr != '\0') {
TRI_set_errno(TRI_ERROR_ILLEGAL_NUMBER);
}
if (errno == ERANGE && (result == HUGE_VAL || result == -HUGE_VAL || result == 0)) {
TRI_set_errno(TRI_ERROR_NUMERIC_OVERFLOW);
}
return result;
}
示例14: TRI_UInt64String
uint64_t TRI_UInt64String (char const* str) {
uint64_t result;
char* endptr;
#if defined(TRI_HAVE_STRTOULL_R)
struct reent buffer;
#elif defined(TRI_HAVE__STRTOULL_R)
struct reent buffer;
#endif
TRI_set_errno(TRI_ERROR_NO_ERROR);
#if defined(TRI_HAVE_STRTOULL_R)
result = strtoull_r(&buffer, str, &endptr, 10);
#elif defined(TRI_HAVE__STRTOULL_R)
result = _strtoull_r(&buffer, str, &endptr, 10);
#elif defined(TRI_HAVE_STRTOUI64)
result = _strtoui64(str, &endptr, 10);
#elif defined(TRI_HAVE_STRTOULL)
result = strtoull(str, &endptr, 10);
#else
#warning cannot convert string to int64
#endif
while (isspace(*endptr)) {
++endptr;
}
if (*endptr != '\0') {
TRI_set_errno(TRI_ERROR_ILLEGAL_NUMBER);
}
if (errno == ERANGE && (result == 0 || result == UINT64_MAX)) {
TRI_set_errno(TRI_ERROR_NUMERIC_OVERFLOW);
}
return result;
}
示例15: TRI_InsertKeyAssociativeSynced
void* TRI_InsertKeyAssociativeSynced (TRI_associative_synced_t* array,
void const* key,
void* element,
bool overwrite) {
uint64_t hash;
uint64_t i;
void* old;
// compute the hash
hash = array->hashKey(array, key);
// search the table
TRI_WriteLockReadWriteLock(&array->_lock);
// check for out-of-memory
if (array->_nrAlloc == array->_nrUsed && ! overwrite) {
TRI_WriteUnlockReadWriteLock(&array->_lock);
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
return NULL;
}
i = hash % array->_nrAlloc;
while (array->_table[i] != NULL && ! array->isEqualKeyElement(array, key, array->_table[i])) {
i = TRI_IncModU64(i, array->_nrAlloc);
}
old = array->_table[i];
// if we found an element, return
if (old != NULL) {
if (overwrite) {
array->_table[i] = element;
}
TRI_WriteUnlockReadWriteLock(&array->_lock);
return old;
}
// add a new element to the associative array
array->_table[i] = element;
array->_nrUsed++;
// if we were adding and the table is more than half full, extend it
if (array->_nrAlloc < 2 * array->_nrUsed) {
ResizeAssociativeSynced(array, (uint32_t) (2 * array->_nrAlloc + 1));
}
TRI_WriteUnlockReadWriteLock(&array->_lock);
return NULL;
}