本文整理汇总了C++中RET_ERR函数的典型用法代码示例。如果您正苦于以下问题:C++ RET_ERR函数的具体用法?C++ RET_ERR怎么用?C++ RET_ERR使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RET_ERR函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _alpm_log
alpm_db_t *_alpm_db_register_sync(alpm_handle_t *handle, const char *treename,
alpm_siglevel_t level)
{
alpm_db_t *db;
_alpm_log(handle, ALPM_LOG_DEBUG, "registering sync database '%s'\n", treename);
#ifndef HAVE_LIBGPGME
if(level != 0 && level != ALPM_SIG_USE_DEFAULT) {
RET_ERR(handle, ALPM_ERR_WRONG_ARGS, NULL);
}
#endif
db = _alpm_db_new(treename, 0);
if(db == NULL) {
RET_ERR(handle, ALPM_ERR_DB_CREATE, NULL);
}
db->ops = &sync_db_ops;
db->handle = handle;
db->siglevel = level;
sync_db_validate(db);
handle->dbs_sync = alpm_list_add(handle->dbs_sync, db);
return db;
}
示例2: strlen
static FILE *create_tempfile(struct dload_payload *payload, const char *localpath)
{
int fd;
FILE *fp;
char *randpath;
size_t len;
/* create a random filename, which is opened with O_EXCL */
len = strlen(localpath) + 14 + 1;
MALLOC(randpath, len, RET_ERR(payload->handle, ALPM_ERR_MEMORY, NULL));
snprintf(randpath, len, "%salpmtmp.XXXXXX", localpath);
if((fd = mkstemp(randpath)) == -1 ||
fchmod(fd, ~(_getumask()) & 0666) ||
!(fp = fdopen(fd, payload->tempfile_openmode))) {
unlink(randpath);
close(fd);
_alpm_log(payload->handle, ALPM_LOG_ERROR,
_("failed to create temporary file for download\n"));
free(randpath);
return NULL;
}
/* fp now points to our alpmtmp.XXXXXX */
free(payload->tempfile_name);
payload->tempfile_name = randpath;
free(payload->remote_name);
STRDUP(payload->remote_name, strrchr(randpath, '/') + 1,
RET_ERR(payload->handle, ALPM_ERR_MEMORY, NULL));
return fp;
}
示例3: _alpm_trans_addtarget
/** Add a target to the transaction.
* @param trans the current transaction
* @param target the name of the target to add
* @return 0 on success, -1 on error (pm_errno is set accordingly)
*/
int _alpm_trans_addtarget(pmtrans_t *trans, char *target)
{
ALPM_LOG_FUNC;
/* Sanity checks */
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
ASSERT(target != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
switch(trans->type) {
case PM_TRANS_TYPE_UPGRADE:
if(_alpm_add_loadtarget(trans, handle->db_local, target) == -1) {
/* pm_errno is set by _alpm_add_loadtarget() */
return(-1);
}
break;
case PM_TRANS_TYPE_REMOVE:
case PM_TRANS_TYPE_REMOVEUPGRADE:
if(_alpm_remove_loadtarget(trans, handle->db_local, target) == -1) {
/* pm_errno is set by _alpm_remove_loadtarget() */
return(-1);
}
break;
case PM_TRANS_TYPE_SYNC:
if(_alpm_sync_addtarget(trans, handle->db_local, handle->dbs_sync, target) == -1) {
/* pm_errno is set by _alpm_sync_loadtarget() */
return(-1);
}
break;
}
return(0);
}
示例4: alpm_trans_release
/** Release a transaction. */
int SYMEXPORT alpm_trans_release(alpm_handle_t *handle)
{
alpm_trans_t *trans;
/* Sanity checks */
CHECK_HANDLE(handle, return -1);
trans = handle->trans;
ASSERT(trans != NULL, RET_ERR(handle, ALPM_ERR_TRANS_NULL, -1));
ASSERT(trans->state != STATE_IDLE, RET_ERR(handle, ALPM_ERR_TRANS_NULL, -1));
int nolock_flag = trans->flags & ALPM_TRANS_FLAG_NOLOCK;
_alpm_trans_free(trans);
handle->trans = NULL;
/* unlock db */
if(!nolock_flag) {
if(_alpm_handle_unlock(handle)) {
_alpm_log(handle, ALPM_LOG_WARNING, _("could not remove lock file %s\n"),
alpm_option_get_lockfile(handle));
alpm_logaction(handle, "warning: could not remove lock file %s\n",
alpm_option_get_lockfile(handle));
}
}
return 0;
}
示例5: alpm_trans_init
/** Initialize the transaction. */
int SYMEXPORT alpm_trans_init(alpm_handle_t *handle, alpm_transflag_t flags,
alpm_trans_cb_event event, alpm_trans_cb_conv conv,
alpm_trans_cb_progress progress)
{
alpm_trans_t *trans;
/* Sanity checks */
CHECK_HANDLE(handle, return -1);
ASSERT(handle->trans == NULL, RET_ERR(handle, ALPM_ERR_TRANS_NOT_NULL, -1));
/* lock db */
if(!(flags & ALPM_TRANS_FLAG_NOLOCK)) {
if(_alpm_handle_lock(handle)) {
RET_ERR(handle, ALPM_ERR_HANDLE_LOCK, -1);
}
}
CALLOC(trans, 1, sizeof(alpm_trans_t), RET_ERR(handle, ALPM_ERR_MEMORY, -1));
trans->flags = flags;
trans->cb_event = event;
trans->cb_conv = conv;
trans->cb_progress = progress;
trans->state = STATE_INITIALIZED;
handle->trans = trans;
return 0;
}
示例6: alpm_trans_release
/** Release a transaction.
* @return 0 on success, -1 on error (pm_errno is set accordingly)
*/
int SYMEXPORT alpm_trans_release()
{
pmtrans_t *trans;
ALPM_LOG_FUNC;
/* Sanity checks */
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
trans = handle->trans;
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
ASSERT(trans->state != STATE_IDLE, RET_ERR(PM_ERR_TRANS_NULL, -1));
_alpm_trans_free(trans);
handle->trans = NULL;
/* unlock db */
if(handle->lckfd != -1) {
while(close(handle->lckfd) == -1 && errno == EINTR);
handle->lckfd = -1;
}
if(_alpm_lckrm()) {
_alpm_log(PM_LOG_WARNING, _("could not remove lock file %s\n"),
alpm_option_get_lockfile());
alpm_logaction("warning: could not remove lock file %s\n",
alpm_option_get_lockfile());
}
return(0);
}
示例7: alpm_remove_pkg
/**
* @brief Add a package removal action to the transaction.
*
* @param handle the context handle
* @param pkg the package to uninstall
*
* @return 0 on success, -1 on error
*/
int SYMEXPORT alpm_remove_pkg(alpm_handle_t *handle, alpm_pkg_t *pkg)
{
const char *pkgname;
alpm_trans_t *trans;
alpm_pkg_t *copy;
/* Sanity checks */
CHECK_HANDLE(handle, return -1);
ASSERT(pkg != NULL, RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1));
ASSERT(handle == pkg->handle, RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1));
trans = handle->trans;
ASSERT(trans != NULL, RET_ERR(handle, ALPM_ERR_TRANS_NULL, -1));
ASSERT(trans->state == STATE_INITIALIZED,
RET_ERR(handle, ALPM_ERR_TRANS_NOT_INITIALIZED, -1));
pkgname = pkg->name;
if(alpm_pkg_find(trans->remove, pkgname)) {
RET_ERR(handle, ALPM_ERR_TRANS_DUP_TARGET, -1);
}
_alpm_log(handle, ALPM_LOG_DEBUG, "adding package %s to the transaction remove list\n",
pkgname);
if(_alpm_pkg_dup(pkg, ©) == -1) {
return -1;
}
trans->remove = alpm_list_add(trans->remove, copy);
return 0;
}
示例8: examine_inside_scaling_none
int examine_inside_scaling_none(void)
{
int i;
double inside;
inside_failure = 0.0;
for (i = 0; i < num_roots; i++) {
inside = expl_graph[roots[i]->id]->inside;
if (i == failure_root_index) {
inside_failure = inside;
if (!(1.0 - inside_failure > 0.0)) {
emit_error("Probability of failure being unity");
RET_ERR(err_invalid_numeric_value);
}
}
else {
if (!(inside > 0.0)) {
emit_error("Probability of an observed goal being non-positive (log_scale: off)");
RET_ERR(err_invalid_numeric_value);
}
}
}
return BP_TRUE;
}
示例9: alpm_db_unregister
/** Unregister a package database. */
int SYMEXPORT alpm_db_unregister(alpm_db_t *db)
{
int found = 0;
alpm_handle_t *handle;
/* Sanity checks */
ASSERT(db != NULL, return -1);
/* Do not unregister a database if a transaction is on-going */
handle = db->handle;
handle->pm_errno = 0;
ASSERT(handle->trans == NULL, RET_ERR(handle, ALPM_ERR_TRANS_NOT_NULL, -1));
if(db == handle->db_local) {
handle->db_local = NULL;
found = 1;
} else {
/* Warning : this function shouldn't be used to unregister all sync
* databases by walking through the list returned by
* alpm_get_syncdbs, because the db is removed from that list here.
*/
void *data;
handle->dbs_sync = alpm_list_remove(handle->dbs_sync,
db, _alpm_db_cmp, &data);
if(data) {
found = 1;
}
}
if(!found) {
RET_ERR(handle, ALPM_ERR_DB_NOT_FOUND, -1);
}
db->ops->unregister(db);
return 0;
}
示例10: pc_export_sw_info_1
/*
* Export probabilities of switches from Prolog to C. Switches is
* a list of switches, each of which takes the form:
*
* sw(Id,InstanceIds,Probs,SmoothCs,Fixed,FixedH),
*
* where
* Id: identifier of the switch
* InstanceIds: list of ids of the instances of the switch
* Probs: current probabilities assigned to the instance switches
* SmoothCs: current pseudo counts assigned to the instance switches
* Fixed: probabilities fixed?
* FixedH: pseudo counts fixed?
*
* The structures for switch instances have been allocated. This
* function only fills out the initial probabilities.
*/
int pc_export_sw_info_1(void)
{
int sw_id,instance_id,fixed,fixed_h;
double prob,smooth;
TERM p_switches, p_switch;
TERM p_instance_list,p_prob_list,p_smooth_list;
TERM p_prob,p_smooth;
p_switches = bpx_get_call_arg(1,1);
while (bpx_is_list(p_switches)) {
/* p_switch: sw(Id,InstList,ProbList,SmoothCList,FixedP,FixedH) */
p_switch = bpx_get_car(p_switches);
sw_id = bpx_get_integer(bpx_get_arg(1,p_switch));
p_instance_list = bpx_get_arg(2,p_switch);
p_prob_list = bpx_get_arg(3,p_switch);
p_smooth_list = bpx_get_arg(4,p_switch);
fixed = bpx_get_integer(bpx_get_arg(5,p_switch));
fixed_h = bpx_get_integer(bpx_get_arg(6,p_switch));
while (bpx_is_list(p_instance_list)) {
instance_id = bpx_get_integer(bpx_get_car(p_instance_list));
p_prob = bpx_get_car(p_prob_list);
p_smooth = bpx_get_car(p_smooth_list);
if (bpx_is_integer(p_prob)) {
prob = (double)bpx_get_integer(p_prob);
}
else if (bpx_is_float(p_prob)) {
prob = bpx_get_float(p_prob);
}
else {
RET_ERR(illegal_arguments);
}
if (bpx_is_integer(p_smooth)) {
smooth = (double)bpx_get_integer(p_smooth);
}
else if (bpx_is_float(p_smooth)) {
smooth = bpx_get_float(p_smooth);
}
else {
RET_ERR(illegal_arguments);
}
switch_instances[instance_id]->inside = prob;
switch_instances[instance_id]->fixed = fixed;
switch_instances[instance_id]->fixed_h = fixed_h;
switch_instances[instance_id]->smooth_prolog = smooth;
p_instance_list = bpx_get_cdr(p_instance_list);
p_prob_list = bpx_get_cdr(p_prob_list);
p_smooth_list = bpx_get_cdr(p_smooth_list);
}
p_switches = bpx_get_cdr(p_switches);
}
return BP_TRUE;
}
示例11: bpinit
/*!
* \brief Inizializza il Buffer Pool.
*
* Alloca la memoria per il Buffer di Playout e inizializza la Free List per la gestione interna della memoria.
* Inizializza la variabile di accesso in Mutua Esclusione alla Free List.
*
* \param bp Il puntatore al Buffer Pool corrente.
* \return 1 in caso di errore, 0 altrimenti.
* \see bpkill
* \see bufferpool.h
* */
int bpinit(buffer_pool * bp)
{
pthread_mutexattr_t mutex_attr;
int i;
if (((bp->bufferpool) =
(bp_slot *) malloc(BP_SLOT_NUM * sizeof(bp_slot))) == NULL) {
return 1;
}
memset(bp->bufferpool, 0, BP_SLOT_NUM * sizeof(bp_slot));
bp->freelist = calloc(BP_SLOT_NUM, sizeof(int));
for (i = 0; i < BP_SLOT_NUM; bp->freelist[i] = i + 1, i++);
bp->freelist[BP_SLOT_NUM - 1] = -1;
bp->flhead = 0;
bp->flcount = 0;
bp->size = BP_SLOT_NUM;
if ((i = pthread_mutexattr_init(&mutex_attr)) > 0)
RET_ERR(i);
if ((i = pthread_mutex_init(&(bp->fl_mutex), &mutex_attr)) > 0)
RET_ERR(i);
// cond initialization
if ((i = pthread_cond_init(&(bp->cond_full), NULL)) > 0)
RET_ERR(i);
return 0;
}
示例12: examine_inside_scaling_log_exp
int examine_inside_scaling_log_exp(void)
{
int i;
double inside;
/* [23 Aug 2007, by yuizumi]
* By the code below, inside_failure can take only a non-zero value
* when `failure' is observed. We can therefore safely use zero as
* an indicator of failure being not observed. Zero is chosen just
* for convenience in implementation of the parallel version.
*/
inside_failure = 0.0;
for (i = 0; i < num_roots; i++) {
inside = expl_graph[roots[i]->id]->inside;
if (i == failure_root_index) {
inside_failure = inside; /* log-scale */
if (!(inside_failure < 0.0)) {
emit_error("Probability of failure being unity");
RET_ERR(err_invalid_numeric_value);
}
}
else {
if (!isfinite(inside)) {
emit_error("Probability of an observed goal being non-positive (log_scale: on)");
RET_ERR(err_invalid_numeric_value);
}
}
}
return BP_TRUE;
}
示例13: strlen
static char *get_sync_dir(alpm_handle_t *handle)
{
size_t len = strlen(handle->dbpath) + 6;
char *syncpath;
struct stat buf;
MALLOC(syncpath, len, RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
sprintf(syncpath, "%s%s", handle->dbpath, "sync/");
if(stat(syncpath, &buf) != 0) {
_alpm_log(handle, ALPM_LOG_DEBUG, "database dir '%s' does not exist, creating it\n",
syncpath);
if(_alpm_makepath(syncpath) != 0) {
free(syncpath);
RET_ERR(handle, ALPM_ERR_SYSTEM, NULL);
}
} else if(!S_ISDIR(buf.st_mode)) {
_alpm_log(handle, ALPM_LOG_WARNING, _("removing invalid file: %s\n"), syncpath);
if(unlink(syncpath) != 0 || _alpm_makepath(syncpath) != 0) {
free(syncpath);
RET_ERR(handle, ALPM_ERR_SYSTEM, NULL);
}
}
return syncpath;
}
示例14: CHECK_HANDLE
/** Register a sync database of packages. */
alpm_db_t SYMEXPORT *alpm_register_syncdb(alpm_handle_t *handle,
const char *treename, alpm_siglevel_t level)
{
alpm_list_t *i;
/* Sanity checks */
CHECK_HANDLE(handle, return NULL);
ASSERT(treename != NULL && strlen(treename) != 0,
RET_ERR(handle, ALPM_ERR_WRONG_ARGS, NULL));
ASSERT(!strchr(treename, '/'), RET_ERR(handle, ALPM_ERR_WRONG_ARGS, NULL));
/* Do not register a database if a transaction is on-going */
ASSERT(handle->trans == NULL, RET_ERR(handle, ALPM_ERR_TRANS_NOT_NULL, NULL));
/* ensure database name is unique */
if(strcmp(treename, "local") == 0) {
RET_ERR(handle, ALPM_ERR_DB_NOT_NULL, NULL);
}
for(i = handle->dbs_sync; i; i = i->next) {
alpm_db_t *d = i->data;
if(strcmp(treename, d->treename) == 0) {
RET_ERR(handle, ALPM_ERR_DB_NOT_NULL, NULL);
}
}
return _alpm_db_register_sync(handle, treename, level);
}
示例15: alpm_trans_prepare
/** Prepare a transaction. */
int SYMEXPORT alpm_trans_prepare(alpm_handle_t *handle, alpm_list_t **data)
{
alpm_trans_t *trans;
/* Sanity checks */
CHECK_HANDLE(handle, return -1);
ASSERT(data != NULL, RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1));
trans = handle->trans;
ASSERT(trans != NULL, RET_ERR(handle, ALPM_ERR_TRANS_NULL, -1));
ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(handle, ALPM_ERR_TRANS_NOT_INITIALIZED, -1));
/* If there's nothing to do, return without complaining */
if(trans->add == NULL && trans->remove == NULL) {
return 0;
}
alpm_list_t *invalid = check_arch(handle, trans->add);
if(invalid) {
if(data) {
*data = invalid;
}
RET_ERR(handle, ALPM_ERR_PKG_INVALID_ARCH, -1);
}
if(trans->add == NULL) {
if(_alpm_remove_prepare(handle, data) == -1) {
/* pm_errno is set by _alpm_remove_prepare() */
return -1;
}
} else {
if(_alpm_sync_prepare(handle, data) == -1) {
/* pm_errno is set by _alpm_sync_prepare() */
return -1;
}
}
if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) {
_alpm_log(handle, ALPM_LOG_DEBUG, "sorting by dependencies\n");
if(trans->add) {
alpm_list_t *add_orig = trans->add;
trans->add = _alpm_sortbydeps(handle, add_orig, trans->remove, 0);
alpm_list_free(add_orig);
}
if(trans->remove) {
alpm_list_t *rem_orig = trans->remove;
trans->remove = _alpm_sortbydeps(handle, rem_orig, NULL, 1);
alpm_list_free(rem_orig);
}
}
trans->state = STATE_PREPARED;
return 0;
}