本文整理汇总了C++中BAIL函数的典型用法代码示例。如果您正苦于以下问题:C++ BAIL函数的具体用法?C++ BAIL怎么用?C++ BAIL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BAIL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FskFSFileRename
FskErr FskFSFileRename(const char *fullPath, const char *newName)
{
int err;
char *p, newPath[PATH_MAX];
FskFileInfo itemInfo;
err = sCheckFullPath(fullPath, kFskPathIsFile);
BAIL_IF_ERR(err);
err = FskFSFileGetFileInfo(fullPath, &itemInfo);
BAIL_IF_ERR(err);
if (itemInfo.filetype == kFskDirectoryItemIsDirectory)
BAIL(kFskErrIsDirectory);
p = FskStrRChr((char *)newName, '/');
if (p)
BAIL(kFskErrOperationFailed); // newName contains path elements
FskStrCopy(newPath, fullPath);
p = FskStrRChr(newPath, '/');
if (p)
*++p = '\0';
FskStrCat(newPath, newName);
err = rename(fullPath, newPath);
if (err == -1)
BAIL(errnoToFskErr(errno));
err = kFskErrNone;
bail:
return err;
}
示例2: pam5_basepair_handle_match
static void
pam5_basepair_handle_match(struct patternMatch *match)
{
struct atom *aAh = match->p->atoms[match->atomIndices[0]];
struct atom *aGv = match->p->atoms[match->atomIndices[1]];
struct atom *aS1 = match->p->atoms[match->atomIndices[2]];
struct atom *aS2 = match->p->atoms[match->atomIndices[3]];
struct atom *vA;
struct bond *bond;
pam5_requires_gromacs(match->p);
BAIL();
init_stack_match();
BAIL();
// S1
// |
// Gv----Ah
// |
// S2
if (aAh->isGrounded) {
vA = makeVirtualAtom(vAh5_type, sp3, 3, 1,
aGv, aS1, aS2, NULL,
axis_pq, axis_pq, 0.0);
bond = makeBond(match->p, vA, aAh, '1');
queueAtom(match->p, vA);
trace_makeVirtualAtom(match, vA);
queueBond(match->p, bond);
trace_makeBond(match, bond);
}
//printMatch(match);
}
示例3: evaluateGradient
void
evaluateGradient(struct configuration *p)
{
struct functionDefinition *fd;
int i;
double gradientCoordinate;
NULLPTR(p);
fd = p->functionDefinition;
NULLPTR(fd);
if (p->gradient == NULL) {
p->gradient = (double *)allocate(sizeof(double) * fd->dimension);
if (fd->dfunc == NULL) {
evaluateGradientFromPotential(p); BAIL();
} else {
(*fd->dfunc)(p); BAIL();
}
fd->gradientEvaluationCount++;
p->parameter = 0.0;
p->maximumCoordinateInGradient = 0.0;
for (i=fd->dimension-1; i>=0; i--) {
CHECKNAN(p->gradient[i]);
gradientCoordinate = fabs(p->gradient[i]);
if (p->maximumCoordinateInGradient < gradientCoordinate) {
p->maximumCoordinateInGradient = gradientCoordinate;
}
}
}
}
示例4: alloc_monitoring_datas
int alloc_monitoring_datas() {
int error = 0;
if (world.config == NULL) {
goto cleanup;
}
qsort(world.stored_data, MAX_ACTIVE_ADDRS,
sizeof(monitoring_data*), sub_storeptrs);
int data_pos = 0;
for(int i = 0; i < world.num_active_addrs; i++) {
uint8_t addr = world.active_addrs[i];
while(world.stored_data[data_pos] != NULL &&
world.stored_data[data_pos]->addr != addr) {
data_pos++;
}
if (world.stored_data[data_pos] == NULL) {
log("Detected PSU at address 0x%02x\n", addr);
//syslog(LOG_INFO, "Detected PSU at address 0x%02x", addr);
world.stored_data[data_pos] = alloc_monitoring_data(addr);
if (world.stored_data[data_pos] == NULL) {
BAIL("allocation failed\n");
}
//reset search pos after alloc (post-sorted addrs may already be alloc'd, need to check again)
data_pos = 0;
continue;
}
if (world.stored_data[data_pos]->addr == addr) {
continue;
}
BAIL("shouldn't get here!\n");
}
cleanup:
return error;
}
示例5: pam5_phosphate_sugar_match
// Sets the phosphate-sugar bond type differently based on the bond
// direction. This allows the phosphate to be closer to one sugar
// than the other, based on the strand direction.
static void
pam5_phosphate_sugar_match(struct patternMatch *match)
{
struct part *p = match->p;
struct atom *aPl = p->atoms[match->atomIndices[0]];
struct atom *aSs = p->atoms[match->atomIndices[1]];
struct bond *b = getBond(p, aPl, aSs);
BAIL();
struct stretch *s = getStretch(p, aPl, aSs);
BAIL();
int reverse;
pam5_requires_gromacs(match->p);
BAIL();
init_stack_match();
BAIL();
switch (b->direction) {
case 'F':
reverse = (b->a1 == aSs);
break;
case 'R':
reverse = (b->a1 == aPl);
break;
default:
ERROR2("pam5_phosphate_sugar_match: bond between ids %d and %d has no direction", aPl->atomID, aSs->atomID);
p->parseError(p->stream);
return;
}
s->stretchType = reverse ? stretch_5_Ss_Pl_3 : stretch_5_Pl_Ss_3 ;
trace_setStretchType(match, s);
//printMatch(match);
}
示例6: FskFSFileOpen
// ---------------------------------------------------------------------
FskErr FskFSFileOpen(const char *fullPath, UInt32 permissions, FskFSFile *frefOut) {
FskErr err;
FskFSFile fref;
FskFileInfo itemInfo;
if (frefOut)
*frefOut = NULL;
err = sCheckFullPath(fullPath, kFskPathIsFile);
BAIL_IF_ERR(err);
err = FskFSFileGetFileInfo(fullPath, &itemInfo);
BAIL_IF_ERR(err);
if (itemInfo.filetype == kFskDirectoryItemIsDirectory)
BAIL(kFskErrIsDirectory);
err = FskMemPtrNewClear(sizeof(FskFSFileRecord), (FskMemPtr*)(void*)&fref);
BAIL_IF_NONZERO(err, err, kFskErrMemFull);
fref->thePermissions = permissions;
fref->theFile = FOPEN(fullPath, sPermsToPermStr(permissions));
if (!fref->theFile) {
FskMemPtrDispose(fref);
BAIL(errnoToFskErr(errno));
}
*frefOut = fref;
bail:
return err;
}
示例7: dircopy
int dircopy(char *base, char *src[], int nsrc)
{
char *dest = NULL;
int baselen = strlen(base) + 1; /* +1 for '/' */
int i, destlen = 0, ret = 0;
#define BAIL() do{ ret = 1; goto bail; } while(0)
for(i = 0; i < nsrc; i++){
int newlen = baselen + strlen(src[i]) + 1;
if(destlen < newlen){
char *tmp = realloc(dest, newlen);
if(!tmp){
perrorf("realloc()");
BAIL();
}
dest = tmp;
}
if(*src[i] != '/')
sprintf(dest, "%s/%s", base, src[i]);
else
strcpy(dest, src[i]);
if(copy(dest, src[i]))
BAIL();
}
bail:
free(dest);
return ret;
}
示例8: nccf_append_att
/* Append string to a named global attribute. Create the attribute if
* it doesn't exist. */
static int
nccf_append_att(int ncid, const char *name, const char *string)
{
char *att_str = NULL;
size_t len, new_len;
int ret;
/* Find out if there is an attribute of this name. */
ret = nc_inq_attlen(ncid, NC_GLOBAL, name, &len);
if (ret == NC_ENOTATT)
{
/* Create the attribute. I will null-terminate this
* attribute. */
if ((ret = nc_put_att_text(ncid, NC_GLOBAL, name,
strlen(string) + 1, string)))
return ret;
}
else if (ret == NC_NOERR)
{
/* The attribute already exists. Get memory to hold the existing
* att plus our version string. Add one for the space, and one
* for a terminating null. */
new_len = len + strlen(string) + 1;
if (!(att_str = malloc(new_len + 1)))
return CF_ENOMEM;
/* Get the existing attribute value. */
if ((ret = nc_get_att_text(ncid, NC_GLOBAL, name, att_str)))
BAIL(CF_ENETCDF);
/* If it's already in the string, our work is done.*/
if (strstr(att_str, string))
{
free(att_str);
return CF_NOERR;
}
/* Append our string to the existing att. */
att_str[len] = 0;
strcat(att_str, " ");
strcat(att_str, string);
/* Delete the existing attribute, so we can rewrite it. */
if ((ret = nc_del_att(ncid, NC_GLOBAL, name)))
BAIL(ret);
/* Rewrite the attribute with our string appended. */
if ((ret = nc_put_att_text(ncid, NC_GLOBAL, name,
strlen(att_str) + 1, att_str)))
BAIL(ret);
}
exit:
if (att_str)
free(att_str);
return ret;
}
示例9: pam5_stack_match
static void
pam5_stack_match(struct patternMatch *match)
{
struct atom *aGv1 = match->p->atoms[match->atomIndices[0]];
struct atom *aGv2 = match->p->atoms[match->atomIndices[1]];
struct atom *aS1a = match->p->atoms[match->atomIndices[2]];
struct atom *aS1b = match->p->atoms[match->atomIndices[3]];
struct atom *aS2a = match->p->atoms[match->atomIndices[4]];
struct atom *aS2b = match->p->atoms[match->atomIndices[5]];
struct atom *vA;
struct atom *vB;
struct bond *bond;
int i;
pam5_requires_gromacs(match->p);
BAIL();
init_stack_match();
BAIL();
// S1a S2b
// | |
// Gv1----Gv2
// | |
// S1b S2a
if (!isExpectedTwist(match->p, aGv1, aGv2, aS1a, aS1b)) {
aS1a = match->p->atoms[match->atomIndices[3]];
aS1b = match->p->atoms[match->atomIndices[2]];
}
if (!isExpectedTwist(match->p, aGv2, aGv1, aS2a, aS2b)) {
aS2a = match->p->atoms[match->atomIndices[5]];
aS2b = match->p->atoms[match->atomIndices[4]];
}
// Atoms are now in canonical orientations. The twist is such that
// the S1a-S2a distance is greater than the S1b-S2b distance in
// BDNA.
for (i=0; i<8 && i < numStruts; i++) {
vA = makeVirtualAtom(vDa_type[i], sp3, 3, 1,
aGv1, aS1a, aS1b, NULL,
vDax_p[i], vDax_q[i], 0.0);
vB = makeVirtualAtom(vDb_type[i], sp3, 3, 1,
aGv2, aS2a, aS2b, NULL,
vDbx_p[i], vDbx_q[i], 0.0);
bond = makeBond(match->p, vA, vB, '1');
queueAtom(match->p, vA);
trace_makeVirtualAtom(match, vA);
queueAtom(match->p, vB);
trace_makeVirtualAtom(match, vB);
queueBond(match->p, bond);
trace_makeBond(match, bond);
}
//printMatch(match);
}
示例10: fsync_dir
static int fsync_dir(const char *name)
{
char *file = (char*) malloc(sizeof(char)*(strlen(name)+1));
strcpy(file, name);
trim_rightmost_path_component(file);
FP(stderr, " fsync-ing '%s'\n", file);
int fd;
if (-1 == (fd = open(file, O_RDONLY))) BAIL("open failed");
if (-1 == fsync(fd)) BAIL("fsync failed");
if (-1 == close(fd)) BAIL("close failed");
free(file);
return 0;
}
示例11: fplay_read_header
/* fplay_read_header
*
* Read the header out of a file, and determine if it is WAV or ILDA.
*/
int fplay_read_header(void) {
char buf[8];
int ret = fplay_read(buf, 8);
if (ret == 0) return 0;
else if (ret != 8) BAIL("short read");
if (!memcmp(buf, "RIFF", 4)) {
uint32_t wav_file_size = *(uint32_t *)(buf + 4);
fplay_read_check(buf, 8);
if (memcmp(buf, "WAVEfmt ", 8)) BAIL("RIFF file not WAV");
return wav_read_file_header(wav_file_size);
}
/* If it's not WAV, it had better be ILDA */
if (memcmp(buf, "ILDA\0\0\0", 7))
BAIL("file is not WAV or ILDA");
fplay_state = buf[7];
/* Read the rest of the header of this particular frame. */
switch (fplay_state) {
case STATE_ILDA_0:
case STATE_ILDA_1:
case STATE_ILDA_4:
case STATE_ILDA_5:
/* 2D, 3D, and formats 4 and 5 */
ret = ilda_read_frame_header();
if (ret < 0) return ret;
if (fplay_points_left < 0) BAIL("negative points in frame");
/* Zero-length means end of file */
if (fplay_points_left == 0)
return 0;
/* Save off the beginning of this frame, in case we
* need to repeat it. */
fplay_frame_start.fptr = fplay_file.fptr;
fplay_frame_start.curr_clust = fplay_file.curr_clust;
fplay_frame_start.dsect = fplay_file.dsect;
ilda_frame_pointcount = fplay_points_left;
break;
default:
BAILV("ilda: bad format %d", fplay_state);
}
return 1;
}
示例12: FskFSFileMap
FskErr FskFSFileMap(const char *fullPath, unsigned char **data, FskInt64 *dataSize, FskFSFileMapping *mapOut)
{
FskErr err = kFskErrNone;
FskFSFileMapping map = NULL;
FskInt64 size;
int fp;
struct stat statbuf;
err = sCheckFullPath(fullPath, kFskPathIsFile);
if (err)
return err;
err = FskMemPtrNewClear(sizeof(FskFSFileMappingRecord), (FskMemPtr*)(void*)&map);
BAIL_IF_ERR(err);
map->file = -1;
fp = open(fullPath, O_RDONLY);
if (fp < 0)
BAIL(errnoToFskErr(errno));
map->file = fp;
fstat(map->file, &statbuf);
size = statbuf.st_size;
if (size > 0xffffffff)
BAIL(kFskErrOperationFailed);
map->length = size;
map->address = mmap(NULL, map->length, PROT_READ, MAP_SHARED, map->file, 0);
if (MAP_FAILED == map->address) {
map->address = NULL;
BAIL(kFskErrOperationFailed);
}
*data = (unsigned char *)map->address;
*dataSize = size;
bail:
if (kFskErrNone != err) {
FskFSFileDisposeMap(map);
map = NULL;
}
*mapOut = map;
return err;
}
示例13: FskSemaphoreNew_
FskErr FskSemaphoreNew_(FskSemaphore *sem, UInt32 value, FSK_SYNCHRONIZATION_DEBUG_ARGS)
#endif
{
FskErr err;
err = FskMemPtrNewClear(sizeof(FskSemaphoreRecord), (FskMemPtr *)sem);
BAIL_IF_ERR(err);
if (((*sem)->hSem = CreateSemaphore(NULL, value, 0x7fffffff, NULL)) == NULL) {
BAIL(kFskErrOperationFailed);
}
FskInstrumentedItemNew(*sem, NULL, &gFskSemaphoreTypeInstrumentation);
#if SUPPORT_INSTRUMENTATION && SUPPORT_SYNCHRONIZATION_DEBUG
if (FskInstrumentedItemHasListeners(*sem)) {
FskSynchronizationInstrMsgRecord msg;
msg.file = file;
msg.line = line;
msg.function = function;
FskInstrumentedItemSendMessage(*sem, kFskSynchronizationInstrMsgSemaphoreNew, &msg);
}
#endif
bail:
if ((err != kFskErrNone) && (*sem != NULL)) {
FskMemPtrDispose(*sem);
*sem = NULL;
}
return err;
}
示例14: FskMutexNew_uninstrumented
FskErr FskMutexNew_uninstrumented(FskMutex *mutex, const char *name)
{
FskErr err;
pthread_mutexattr_t attr;
err = FskMemPtrNewClear(sizeof(FskMutexRecord), (FskMemPtr *)mutex);
BAIL_IF_ERR(err);
if ((pthread_mutexattr_init(&attr) != 0) ||
(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0) ||
(pthread_mutex_init(&(*mutex)->mutex, &attr) != 0)) {
BAIL(kFskErrOperationFailed);
}
#if SUPPORT_INSTRUMENTATION
(*mutex)->name = FskStrDoCopy_Untracked(name);
#endif
bail:
pthread_mutexattr_destroy(&attr);
if ((err != kFskErrNone) && (*mutex != NULL)) {
#if SUPPORT_INSTRUMENTATION
FskMemPtrDispose((FskMemPtr)(*mutex)->name);
#endif
FskMemPtrDispose(*mutex);
*mutex = NULL;
}
return err;
}
示例15: BAIL_ON_FAILURE
//
// convert unicode string to auth type
//
HRESULT
Wstr2AuthType
(
IN LPCWSTR pszSrc,
OUT PIHV_AUTH_TYPE pAuthType
)
{
HRESULT hr = S_OK;
DWORD dwIndex = 0;
if ( (!pAuthType) || (!pszSrc) )
{
hr = E_INVALIDARG;
BAIL_ON_FAILURE( hr );
}
for ( dwIndex = 0; dwIndex < MAX_AUTH_TYPES; dwIndex++ )
{
if ( 0 == wcscmp( gppszIhvAuthTypes[dwIndex], pszSrc ) )
{
(*pAuthType) = (IHV_AUTH_TYPE) dwIndex;
BAIL( );
}
}
// String not found.
hr = E_INVALIDARG;
BAIL_ON_FAILURE( hr );
error:
return hr;
}