本文整理汇总了C++中DIE函数的典型用法代码示例。如果您正苦于以下问题:C++ DIE函数的具体用法?C++ DIE怎么用?C++ DIE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DIE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: string_linked_list_init
StringLinkedList *
string_linked_list_init(void)
{
StringLinkedList *sll = malloc(sizeof(StringLinkedList));
if (sll == NULL) {
DIE("ERROR: Not enough memory to allocate StringLinkedList")
}
sll->head = NULL;
sll->tail = NULL;
sll->len = 0;
return sll;
}
示例2: parse_version_word
static void
parse_version_word(char *word, StringLinkedList *sll)
{
if (expr == NULL) {
setup_version_regex();
}
int ovecsize = 0;
if (pcre_fullinfo(expr, NULL, PCRE_INFO_CAPTURECOUNT, &ovecsize) != 0) {
DIE("ERROR: Problem calling pcre_fullinfo")
}
ovecsize = (ovecsize + 1) * 3;
int *ovector = calloc(ovecsize, sizeof(int));
if (ovector == NULL) {
DIE("ERROR: Not enough memory to allocate ovector")
}
int offset = 0;
int flags = 0;
char *part;
while (0 < pcre_exec(expr, 0, word, strlen(word), offset, flags, ovector, ovecsize)) {
part = malloc((WORD_MAX_LEN+1) * sizeof(char));
if (part == NULL) {
DIE("ERROR: Not enough memory to allocate word")
}
snprintf(part, WORD_MAX_LEN+1, "%.*s", ovector[1]-ovector[0], word+ovector[0]);
string_linked_list_append(sll, part);
offset = ovector[1];
flags |= PCRE_NOTBOL;
}
free(ovector);
}
示例3: computeReserve
/*
Compute reduced heap size by reserving area and rounding down to
nearest page.
*/
double
computeReserve(double rate, int phases)
{
assert(rate > 1.0);
if (phases == 0) /* not concurrent */
return 0.0;
else if (phases == 1) /* concurrent */
return rate / (rate + 1.0);
else if (phases == 2) /* concurrent - non-committing, committing */
return (rate + 1.0) / (rate * rate + rate + 1.0);
DIE("invalid phases");
return 0.0; /* NOTREACHED */
}
示例4: WaitChild
int WaitChild(pid_t pid, const char *name) {
int err, status;
do {
err = waitpid(pid, &status, 0);
} while (err == -1 && errno == EINTR);
if (err == -1) {
DIE("wait on %s (pid %d) failed\n", name, pid);
}
return status;
}
示例5: add_to_common_env
void add_to_common_env(char *key, char *value)
{
#ifndef EXCLUDE_CGI
common_cgi_env = realloc(common_cgi_env, (common_cgi_env_count + 2) * (sizeof(char *)));
if (common_cgi_env== NULL) {
DIE("Unable to allocate memory for common CGI environment variable.");
}
common_cgi_env[common_cgi_env_count] = env_gen_extra(key,value, 0);
if (common_cgi_env[common_cgi_env_count] == NULL) {
/* errors already reported */
DIE("memory allocation failure in add_to_common_env");
}
common_cgi_env[++common_cgi_env_count] = NULL;
/* I find it hard to believe that somebody would actually
* make 90+ *common* CGI variables, but it's always better
* to be safe.
*/
if (common_cgi_env_count > CGI_ENV_MAX) {
DIE("far too many common CGI environment variables added.");
}
#endif // !EXCLUDE_CGI
}
示例6: loadRom
static void loadRom()
{
const char * file = S9xGetFilename(FILE_ROM);
printf("ROM: %s\n", file);
if (!Memory.LoadROM(file))
DIE("Loading ROM failed");
file = S9xGetFilename(FILE_SRAM);
printf("SRAM: %s\n", file);
Memory.LoadSRAM(file);
}
示例7: glfwWindowHint
Window::Window(Game* parent)
{
width = height = 600;
game = parent;
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
windowHandle = glfwCreateWindow(width, height, "Grass", NULL, NULL);
glfwSetWindowPos(windowHandle,800,30);
if (!windowHandle)
DIE("Failed to create window");
glfwMakeContextCurrent(windowHandle);
}
示例8: recv_c
int recv_c(int socket, byte *recvbuf, int bufsize) {
LOG_DEBUG(TAG_CMD, "Receiving command");
int bytes_total = 0;
int bytes_received = 0;
int bytes_missing = CMD_HEADER_LEN;
uint16_t pl_len = 0;
// Receive header
while (bytes_missing > 0) {
bytes_received = recv(socket, recvbuf+bytes_total, bytes_missing, 0);
if (bytes_received == 0) {
return 0;
} else if (bytes_total > bufsize) {
DIE(TAG_CMD, "Recvbuf overflow");
}
bytes_total += bytes_received;
bytes_missing -= bytes_received;
}
// Check length of the packet and receive more data if needed
memcpy(&pl_len, recvbuf+CMD_PL_LEN_OFFSET, sizeof(uint16_t));
pl_len = ntohs(pl_len);
bytes_received = 0;
bytes_missing = pl_len;
while (bytes_missing > 0) {
bytes_received = recv(socket, recvbuf+bytes_total, bytes_missing, 0);
if (bytes_received == 0) {
LOG_WARN(TAG_CMD, "GUI disconnected");
return 0;
} else if (bytes_total > bufsize) {
DIE(TAG_CMD, "Recvbuf overflow");
}
bytes_total += bytes_received;
bytes_missing -= bytes_received;
}
LOG_DEBUG(TAG_CMD, "Received %d bytes", bytes_total);
return bytes_total;
}
示例9: close_files
static void close_files(void)
{
size_t n_files = sizeof(files) / sizeof(files[0]);
size_t i;
int rc;
for (i = 0; i < n_files; i++) {
rc = close(fds[i]);
DIE(rc < 0, "close");
}
free(fds);
}
示例10: show_time
/* based on show_diff_time from eachfile.c */
void show_time(FILE *out, char T, time_t val)
{
char buf[ELC_TIMEBUFSIZ];
putc(T, out);
putc('(', out);
if (! strftime(buf, ELC_TIMEBUFSIZ, "%Y%m%d-%H%M%S", localtime(&val)) )
DIE("strftime");
fputs(buf, out);
fputs(") ", out);
}
示例11: flytec_pbrtr
static void
flytec_pbrtr(flytec_t *flytec, track_t *track, void (*callback)(void *, const char *), void *data)
{
char buf[9];
if (snprintf(buf, sizeof buf, "PBRTR,%02d", track->index) != 8)
DIE("sprintf", 0);
flytec_puts_nmea(flytec, buf);
flytec_expectc(flytec, XOFF);
char line[1024];
while (flytec_gets(flytec, line, sizeof line))
callback(data, line);
flytec_expectc(flytec, XON);
}
示例12: flytec_puts_nmea
static void
flytec_puts_nmea(flytec_t *flytec, char *s)
{
int checksum = 0;
char *p;
for (p = s; *p; ++p)
checksum ^= (unsigned char) *p;
int len = strlen(s) + 7;
char *buf = xmalloc(len);
memset(buf, 0, len);
if (snprintf(buf, len, "$%s*%02X\r\n", s, checksum) != len - 1)
DIE("snprintf", 0);
if (flytec->logfile)
fprintf(flytec->logfile, "> %s", buf);
int rc;
do {
rc = write(flytec->fd, buf, len);
} while (rc == -1 && errno == EINTR);
if (rc == -1)
DIE("write", errno);
free(buf);
}
示例13: create_iocp_accept
static void create_iocp_accept(void)
{
BOOL bRet;
memset(&ac, 0, sizeof(ac));
/* Create simple socket for acceptance */
ac.sockfd = socket(PF_INET, SOCK_STREAM, 0);
DIE(ac.sockfd == INVALID_SOCKET, "socket");
/* Launch overlapped connection accept through AcceptEx. */
bRet = AcceptEx(
listenfd,
ac.sockfd,
ac.buffer,
0,
128,
128,
&ac.len,
&ac.ov);
DIE(bRet == FALSE && WSAGetLastError() != ERROR_IO_PENDING, "AcceptEx");
}
示例14: pdo_sqlsrv_handle_stmt_error
// PDO error handler for the statement context.
bool pdo_sqlsrv_handle_stmt_error( sqlsrv_context& ctx, unsigned int sqlsrv_error_code, bool warning TSRMLS_DC,
va_list* print_args )
{
pdo_stmt_t* pdo_stmt = reinterpret_cast<pdo_stmt_t*>( ctx.driver());
SQLSRV_ASSERT( pdo_stmt != NULL && pdo_stmt->dbh != NULL, "pdo_sqlsrv_handle_stmt_error: Null statement or dbh passed" );
sqlsrv_error_auto_ptr error;
if( sqlsrv_error_code != SQLSRV_ERROR_ODBC ) {
core_sqlsrv_format_driver_error( ctx, get_error_message( sqlsrv_error_code ), error, SEV_ERROR TSRMLS_CC, print_args );
}
else {
bool err = core_sqlsrv_get_odbc_error( ctx, 1, error, SEV_ERROR TSRMLS_CC );
SQLSRV_ASSERT( err == true, "No ODBC error was found" );
}
SQLSRV_STATIC_ASSERT( sizeof( error->sqlstate ) <= sizeof( pdo_stmt->error_code ));
strcpy_s( pdo_stmt->error_code, sizeof( pdo_stmt->error_code ), reinterpret_cast<const char*>( error->sqlstate ));
switch( pdo_stmt->dbh->error_mode ) {
case PDO_ERRMODE_EXCEPTION:
if( !warning ) {
pdo_sqlsrv_throw_exception( error TSRMLS_CC );
}
ctx.set_last_error( error );
break;
case PDO_ERRMODE_WARNING:
if( !warning ) {
unsigned int msg_len = strlen( reinterpret_cast<const char*>( error->native_message )) + SQL_SQLSTATE_BUFSIZE
+ MAX_DIGITS + 1;
sqlsrv_malloc_auto_ptr<char> msg;
msg = static_cast<char*>( sqlsrv_malloc( msg_len ));
core_sqlsrv_format_message( msg, msg_len, WARNING_TEMPLATE, error->sqlstate, error->native_code,
error->native_message );
php_error( E_WARNING, msg );
sqlsrv_free( msg );
}
ctx.set_last_error( error );
break;
case PDO_ERRMODE_SILENT:
ctx.set_last_error( error );
break;
default:
DIE( "Unknown error mode. %1!d!", pdo_stmt->dbh->error_mode );
break;
}
// return error ignored = true for warnings.
return ( warning ? true : false );
}
示例15: print
void print(elem *hashtable, int size, char *file_name)
{
int i;
FILE *fd;
if(file_name != NULL)
{
fd = fopen(file_name, "a");
DIE(fd == NULL, "[print] Error opening file.");
}
for(i = 0; i < size; i++)
{
if(hashtable[i].next != NULL)
{
elem *temp = hashtable[i].next;
if(file_name != NULL)
{
while(temp != NULL)
{
if(temp->next == NULL)
fprintf(fd, "%s", temp->value); /* Print without the last space */
else
fprintf(fd, "%s ", temp->value);
temp = temp->next;
}
}else
{
while(temp != NULL)
{
if(temp->next == NULL)
printf("%s", temp->value);
else
printf("%s ", temp->value);
temp = temp->next;
}
}
if(file_name != NULL)
fprintf(fd, "\n");
else
printf("\n");
}
}
if(file_name != NULL)
fclose(fd);
}