本文整理汇总了C++中safe_malloc函数的典型用法代码示例。如果您正苦于以下问题:C++ safe_malloc函数的具体用法?C++ safe_malloc怎么用?C++ safe_malloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了safe_malloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: make_gesture_array
gesture*
make_gesture_array(u_int size)
{
return((gesture*)safe_malloc(size * sizeof(gesture)));
}
示例2: send_file_chunk
static int
send_file_chunk (guestfs_h *g, int cancel, const char *buf, size_t buflen)
{
uint32_t len;
ssize_t r;
guestfs_chunk chunk;
XDR xdr;
CLEANUP_FREE char *msg_out = NULL;
size_t msg_out_size;
/* Allocate the chunk buffer. Don't use the stack to avoid
* excessive stack usage and unnecessary copies.
*/
msg_out = safe_malloc (g, GUESTFS_MAX_CHUNK_SIZE + 4 + 48);
xdrmem_create (&xdr, msg_out + 4, GUESTFS_MAX_CHUNK_SIZE + 48, XDR_ENCODE);
/* Serialize the chunk. */
chunk.cancel = cancel;
chunk.data.data_len = buflen;
chunk.data.data_val = (char *) buf;
if (!xdr_guestfs_chunk (&xdr, &chunk)) {
error (g, _("xdr_guestfs_chunk failed (buf = %p, buflen = %zu)"),
buf, buflen);
xdr_destroy (&xdr);
return -1;
}
len = xdr_getpos (&xdr);
xdr_destroy (&xdr);
/* Reduce the size of the outgoing message buffer to the real length. */
msg_out = safe_realloc (g, msg_out, len + 4);
msg_out_size = len + 4;
xdrmem_create (&xdr, msg_out, 4, XDR_ENCODE);
xdr_uint32_t (&xdr, &len);
/* Did the daemon send a cancellation message? */
r = check_daemon_socket (g);
if (r == -2) {
debug (g, "got daemon cancellation");
return -2;
}
if (r == -1)
return -1;
if (r == 0) {
guestfs_int_unexpected_close_error (g);
child_cleanup (g);
return -1;
}
/* Send the chunk. */
r = g->conn->ops->write_data (g, g->conn, msg_out, msg_out_size);
if (r == -1)
return -1;
if (r == 0) {
guestfs_int_unexpected_close_error (g);
child_cleanup (g);
return -1;
}
return 0;
}
示例3: output_data
static int output_data(char *buf, int32 nbytes)
{
FLAC__int32 *oggbuf;
FLAC__int16 *s;
int i;
int nch = (dpm.encoding & PE_MONO) ? 1 : 2;
FLAC_ctx *ctx = flac_ctx;
if (dpm.fd < 0)
return 0;
if (ctx == NULL) {
ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "FLAC stream is not initialized");
return -1;
}
oggbuf = (FLAC__int32 *)safe_malloc(nbytes * sizeof(FLAC__int32) / nch);
/*
packing 16 -> 32 bit sample
*/
s = (FLAC__int16 *)buf;
for (i = 0; i < nbytes / nch; i++) {
oggbuf[i] = *s++;
}
#ifdef LEGACY_FLAC
#ifdef AU_OGGFLAC
if (flac_options.isogg) {
ctx->state.ogg = OggFLAC__stream_encoder_get_state(ctx->encoder.ogg.stream);
if (ctx->state.ogg != OggFLAC__STREAM_ENCODER_OK) {
if (ctx->state.ogg == OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR) {
ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "FLAC stream verify error (%s)",
FLAC__StreamDecoderStateString[OggFLAC__stream_encoder_get_verify_decoder_state(ctx->encoder.ogg.stream)]);
}
ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "cannot encode OggFLAC stream (%s)",
OggFLAC__StreamEncoderStateString[ctx->state.ogg]);
flac_session_close();
return -1;
}
if (!OggFLAC__stream_encoder_process_interleaved(ctx->encoder.ogg.stream, oggbuf,
nbytes / nch / 2)) {
ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "cannot encode OggFLAC stream");
flac_session_close();
return -1;
}
}
else
#endif /* AU_OGGFLAC */
if (flac_options.seekable) {
ctx->state.s_flac = FLAC__seekable_stream_encoder_get_state(ctx->encoder.flac.s_stream);
if (ctx->state.s_flac != FLAC__STREAM_ENCODER_OK) {
if (ctx->state.s_flac == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR |
FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA) {
ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "FLAC stream verify error (%s)",
FLAC__SeekableStreamDecoderStateString[FLAC__seekable_stream_encoder_get_verify_decoder_state(ctx->encoder.flac.s_stream)]);
}
else {
ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "cannot encode FLAC stream (%s)",
FLAC__SeekableStreamEncoderStateString[ctx->state.s_flac]);
}
flac_session_close();
return -1;
}
if (!FLAC__seekable_stream_encoder_process_interleaved(ctx->encoder.flac.s_stream, oggbuf,
nbytes / nch / 2 )) {
ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "cannot encode FLAC stream");
flac_session_close();
return -1;
}
}
else
{
ctx->state.flac = FLAC__stream_encoder_get_state(ctx->encoder.flac.stream);
if (ctx->state.flac != FLAC__STREAM_ENCODER_OK) {
if (ctx->state.flac == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR |
FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA) {
ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "FLAC stream verify error (%s)",
FLAC__StreamDecoderStateString[FLAC__stream_encoder_get_verify_decoder_state(ctx->encoder.flac.stream)]);
}
else {
ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "cannot encode FLAC stream (%s)",
FLAC__StreamEncoderStateString[ctx->state.flac]);
}
flac_session_close();
return -1;
}
if (!FLAC__stream_encoder_process_interleaved(ctx->encoder.flac.stream, oggbuf,
nbytes / nch / 2 )) {
ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "cannot encode FLAC stream");
flac_session_close();
return -1;
}
}
#else /* !LEGACY_FLAC */
ctx->state.flac = FLAC__stream_encoder_get_state(ctx->encoder.flac.stream);
//.........这里部分代码省略.........
示例4: vmi_init_private
static status_t
vmi_init_private(
vmi_instance_t *vmi,
uint32_t flags,
uint64_t id,
const char *name,
vmi_config_t config)
{
uint32_t access_mode = flags & 0x0000FFFF;
uint32_t init_mode = flags & 0x00FF0000;
uint32_t config_mode = flags & 0xFF000000;
status_t status = VMI_FAILURE;
/* allocate memory for instance structure */
*vmi = (vmi_instance_t) safe_malloc(sizeof(struct vmi_instance));
memset(*vmi, 0, sizeof(struct vmi_instance));
/* initialize instance struct to default values */
dbprint(VMI_DEBUG_CORE, "LibVMI Version 0.11.0\n"); //TODO change this with each release
/* save the flags and init mode */
(*vmi)->flags = flags;
(*vmi)->init_mode = init_mode;
(*vmi)->config_mode = config_mode;
/* the config hash table is set up later based on mode */
(*vmi)->config = NULL;
/* set page mode to unknown */
(*vmi)->page_mode = VMI_PM_UNKNOWN;
/* setup the caches */
pid_cache_init(*vmi);
sym_cache_init(*vmi);
rva_cache_init(*vmi);
v2p_cache_init(*vmi);
if ( init_mode & VMI_INIT_SHM_SNAPSHOT ) {
#if ENABLE_SHM_SNAPSHOT == 1
v2m_cache_init(*vmi);
#else
errprint("LibVMI wasn't compiled with SHM support!\n");
status = VMI_FAILURE;
goto error_exit;
#endif
}
/* connecting to xen, kvm, file, etc */
if (VMI_FAILURE == set_driver_type(*vmi, access_mode, id, name)) {
goto error_exit;
}
/* driver-specific initilization */
if (VMI_FAILURE == driver_init(*vmi)) {
goto error_exit;
}
dbprint(VMI_DEBUG_CORE, "--completed driver init.\n");
/* resolve the id and name */
if (VMI_FAILURE == set_id_and_name(*vmi, access_mode, id, name)) {
goto error_exit;
}
/* init vmi for specific file/domain through the driver */
if (VMI_FAILURE == driver_init_vmi(*vmi)) {
goto error_exit;
}
/* setup the page offset size */
if (VMI_FAILURE == init_page_offset(*vmi)) {
goto error_exit;
}
/* get the memory size */
if (driver_get_memsize(*vmi, &(*vmi)->allocated_ram_size, &(*vmi)->max_physical_address) == VMI_FAILURE) {
errprint("Failed to get memory size.\n");
goto error_exit;
}
dbprint(VMI_DEBUG_CORE, "**set size = %"PRIu64" [0x%"PRIx64"]\n", (*vmi)->size,
(*vmi)->size);
// for file mode we need os-specific heuristics to deduce the architecture
// for live mode, having arch_interface set even in VMI_PARTIAL mode
// allows use of dtb-based translation methods.
if (VMI_FILE != (*vmi)->mode) {
if(VMI_FAILURE == arch_init(*vmi)) {
if (init_mode & VMI_INIT_COMPLETE) {
dbprint(VMI_DEBUG_CORE, "--failed to determine architecture of live vm and INIT_COMPLETE.\n");
goto error_exit;
} else {
dbprint(VMI_DEBUG_CORE, "--failed to determine architecture of live vm and INIT_PARTIAL, continuing.\n");
}
} else {
dbprint(VMI_DEBUG_CORE, "--succesfully completed architecture init.\n");
}
}
/* we check VMI_INIT_COMPLETE first as
VMI_INIT_PARTIAL is not exclusive */
//.........这里部分代码省略.........
示例5: guestfs_int_send
int
guestfs_int_send (guestfs_h *g, int proc_nr,
uint64_t progress_hint, uint64_t optargs_bitmask,
xdrproc_t xdrp, char *args)
{
struct guestfs_message_header hdr;
XDR xdr;
uint32_t len;
int serial = g->msg_next_serial++;
ssize_t r;
CLEANUP_FREE char *msg_out = NULL;
size_t msg_out_size;
if (!g->conn) {
guestfs_int_unexpected_close_error (g);
return -1;
}
/* We have to allocate this message buffer on the heap because
* it is quite large (although will be mostly unused). We
* can't allocate it on the stack because in some environments
* we have quite limited stack space available, notably when
* running in the JVM.
*/
msg_out = safe_malloc (g, GUESTFS_MESSAGE_MAX + 4);
xdrmem_create (&xdr, msg_out + 4, GUESTFS_MESSAGE_MAX, XDR_ENCODE);
/* Serialize the header. */
hdr.prog = GUESTFS_PROGRAM;
hdr.vers = GUESTFS_PROTOCOL_VERSION;
hdr.proc = proc_nr;
hdr.direction = GUESTFS_DIRECTION_CALL;
hdr.serial = serial;
hdr.status = GUESTFS_STATUS_OK;
hdr.progress_hint = progress_hint;
hdr.optargs_bitmask = optargs_bitmask;
if (!xdr_guestfs_message_header (&xdr, &hdr)) {
error (g, _("xdr_guestfs_message_header failed"));
return -1;
}
/* Serialize the args. If any, because some message types
* have no parameters.
*/
if (xdrp) {
if (!(*xdrp) (&xdr, args, 0)) {
error (g, _("dispatch failed to marshal args"));
return -1;
}
}
/* Get the actual length of the message, resize the buffer to match
* the actual length, and write the length word at the beginning.
*/
len = xdr_getpos (&xdr);
xdr_destroy (&xdr);
msg_out = safe_realloc (g, msg_out, len + 4);
msg_out_size = len + 4;
xdrmem_create (&xdr, msg_out, 4, XDR_ENCODE);
xdr_uint32_t (&xdr, &len);
/* Look for stray daemon cancellation messages from earlier calls
* and ignore them.
*/
r = check_daemon_socket (g);
/* r == -2 (cancellation) is ignored */
if (r == -1)
return -1;
if (r == 0) {
guestfs_int_unexpected_close_error (g);
child_cleanup (g);
return -1;
}
/* Send the message. */
r = g->conn->ops->write_data (g, g->conn, msg_out, msg_out_size);
if (r == -1)
return -1;
if (r == 0) {
guestfs_int_unexpected_close_error (g);
child_cleanup (g);
return -1;
}
return serial;
}
示例6: safe_malloc
driver_exec_t *driver_exec_create(select_group_t *group, char *process, char *name)
{
driver_exec_t *driver_exec = (driver_exec_t*) safe_malloc(sizeof(driver_exec_t));
message_options_t options[2];
/* Declare some WIN32 variables needed for starting the sub-process. */
#ifdef WIN32
STARTUPINFOA startupInfo;
PROCESS_INFORMATION processInformation;
SECURITY_ATTRIBUTES sa;
#endif
driver_exec->process = process;
driver_exec->group = group;
driver_exec->name = name ? name : process;
/* Subscribe to the messages we care about. */
message_subscribe(MESSAGE_DATA_IN, handle_message, driver_exec);
/* Set up the session options and create the session. */
options[0].name = "name";
options[0].value.s = driver_exec->name;
options[1].name = NULL;
driver_exec->session_id = message_post_create_session(options);
#ifdef WIN32
/* Create a security attributes structure. This is required to inherit handles. */
ZeroMemory(&sa, sizeof(SECURITY_ATTRIBUTES));
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
/* Create the anonymous pipes. */
if(!CreatePipe(&driver_exec->exec_stdin[PIPE_READ], &driver_exec->exec_stdin[PIPE_WRITE], &sa, 0))
DIE("exec: Couldn't create pipe for stdin");
if(!CreatePipe(&driver_exec->exec_stdout[PIPE_READ], &driver_exec->exec_stdout[PIPE_WRITE], &sa, 0))
DIE("exec: Couldn't create pipe for stdout");
fprintf(stderr, "Attempting to load the program: %s\n", driver_exec->process);
/* Initialize the STARTUPINFO structure. */
ZeroMemory(&startupInfo, sizeof(STARTUPINFO));
startupInfo.cb = sizeof(STARTUPINFO);
startupInfo.dwFlags = STARTF_USESTDHANDLES;
startupInfo.hStdInput = driver_exec->exec_stdin[PIPE_READ];
startupInfo.hStdOutput = driver_exec->exec_stdout[PIPE_WRITE];
startupInfo.hStdError = driver_exec->exec_stdout[PIPE_WRITE];
/* Initialize the PROCESS_INFORMATION structure. */
ZeroMemory(&processInformation, sizeof(PROCESS_INFORMATION));
/* Create the actual process with an overly-complicated CreateProcess function. */
if(!CreateProcessA(NULL, driver_exec->process, 0, &sa, TRUE, CREATE_NO_WINDOW, 0, NULL, &startupInfo, &processInformation))
{
fprintf(stderr, "Failed to create the process");
exit(1);
}
/* Save the process id and the handle. */
driver_exec->pid = processInformation.dwProcessId;
driver_exec->exec_handle = processInformation.hProcess;
/* Close the duplicate pipes we created -- this lets us detect the proicess termination. */
CloseHandle(driver_exec->exec_stdin[PIPE_READ]);
CloseHandle(driver_exec->exec_stdout[PIPE_WRITE]);
CloseHandle(driver_exec->exec_stdout[PIPE_WRITE]);
fprintf(stderr, "Successfully created the process!\n\n");
/* Create a socket_id value - this is a totally arbitrary value that's only used so we can find this entry later. */
driver_exec->socket_id = --driver_exec->socket_id;
/* On Windows, add the sub-process's stdout as a pipe. */
select_group_add_pipe(driver_exec->group, driver_exec->socket_id, driver_exec->exec_stdout[PIPE_READ], driver_exec);
select_set_recv(driver_exec->group, driver_exec->socket_id, exec_callback);
select_set_closed(driver_exec->group, driver_exec->socket_id, exec_closed_callback);
#else
LOG_INFO("Attempting to start process '%s'...", driver_exec->process);
/* Create communication channels. */
if(pipe(driver_exec->pipe_stdin) == -1)
{
LOG_FATAL("exec: couldn't create pipe (%d)", errno);
exit(1);
}
if(pipe(driver_exec->pipe_stdout) == -1)
{
LOG_FATAL("exec: couldn't create pipe (%d)", errno);
exit(1);
}
driver_exec->pid = fork();
if(driver_exec->pid == -1)
{
LOG_FATAL("exec: couldn't create process (%d)", errno);
exit(1);
}
//.........这里部分代码省略.........
示例7: ea_setxattr_rcs
int ea_setxattr_rcs(const char *path, const char *name, const char *value, size_t size)
{
metadata_t *metadata;
version_t *version;
rcs_ignore_deleted = 1;
metadata = rcs_translate_to_metadata(path, rcs_version_path);
rcs_ignore_deleted = 0;
if (!metadata)
return -ENOENT;
if (!strcmp(name,"rcs.purge"))
{
/* Copy the value to NUL-terminate it */
char *local;
local = safe_malloc(size + 1);
local[size] = '\0';
memcpy(local, value, size);
// Get the full path to the metadatafile
char *mdfile=helper_build_meta_name(path, METADATA_PREFIX);
if (!mdfile)
return -ENOENT;
int c=1; // how many versions to delete
int vnum=1; // number of versions
if(!strcmp(local,"A")) {
// Delete them all
// we don't have to count the versions
// we just leave c and vnum at 1
} else {
// we have a number, so set c to it
c=atoi(local);
// Count the number of versions there are
version = metadata->md_versions;
while(version->v_next) {
version=version->v_next;
vnum++;
}
}
/* Let's do this... Crawl through the list, nulling
* next's and unlinking files
*/
version_t *next;
version = metadata->md_versions;
if(c >= vnum) {
// we're toasting them all...
while(version) {
//unlink file.. scary!
unlink(version->v_rfile);
/* No need to clean up version data.
* This is done later by rcs_free_metadata */
version=version->v_next;
}
// Free the metadata from cache
cache_drop_metadata(metadata);
rcs_free_metadata(metadata);
// kill the metadata file too.. SCARY!!!
unlink(mdfile);
} else {
// cull
vnum-=c; // number of versions we want to _keep_.
while(version) {
if(vnum > 1) {
// we want to keep this version
vnum--;
version=version->v_next;
}
else if (vnum == 1) {
// this is the last version to keep
vnum--;
next=version->v_next;
version->v_next = NULL;
version=next;
}
else {
//delete this version
//unlink file.. scary!
unlink(version->v_rfile);
next=version->v_next;
free(version->v_rfile);
free(version);
version=next;
}
}
// We've made changes to the metadata, and got at least one
// version left.. need to update it
if (write_metadata_file(mdfile, metadata) == -1) {
free(mdfile);
return -errno;
}
}
//.........这里部分代码省略.........
示例8: mutt_parse_hook
//.........这里部分代码省略.........
/* At this stage remain only message-hooks, reply-hooks, send-hooks,
* send2-hooks, save-hooks, and fcc-hooks: All those allowing full
* patterns. If given a simple regexp, we expand $default_hook.
*/
strfcpy (tmp, pattern.data, sizeof (tmp));
mutt_check_simple (tmp, sizeof (tmp), DefaultHook);
FREE (&pattern.data);
memset (&pattern, 0, sizeof (pattern));
pattern.data = safe_strdup (tmp);
}
if (data & (MUTT_MBOXHOOK | MUTT_SAVEHOOK | MUTT_FCCHOOK))
{
strfcpy (path, command.data, sizeof (path));
mutt_expand_path (path, sizeof (path));
FREE (&command.data);
memset (&command, 0, sizeof (command));
command.data = safe_strdup (path);
}
/* check to make sure that a matching hook doesn't already exist */
for (ptr = Hooks; ptr; ptr = ptr->next)
{
if (ptr->type == data &&
ptr->rx.not == not &&
!mutt_strcmp (pattern.data, ptr->rx.pattern))
{
if (data & (MUTT_FOLDERHOOK | MUTT_SENDHOOK | MUTT_SEND2HOOK | MUTT_MESSAGEHOOK | MUTT_ACCOUNTHOOK | MUTT_REPLYHOOK | MUTT_CRYPTHOOK))
{
/* these hooks allow multiple commands with the same
* pattern, so if we've already seen this pattern/command pair, just
* ignore it instead of creating a duplicate */
if (!mutt_strcmp (ptr->command, command.data))
{
FREE (&command.data);
FREE (&pattern.data);
return 0;
}
}
else
{
/* other hooks only allow one command per pattern, so update the
* entry with the new command. this currently does not change the
* order of execution of the hooks, which i think is desirable since
* a common action to perform is to change the default (.) entry
* based upon some other information. */
FREE (&ptr->command);
ptr->command = command.data;
FREE (&pattern.data);
return 0;
}
}
if (!ptr->next)
break;
}
if (data & (MUTT_SENDHOOK | MUTT_SEND2HOOK | MUTT_SAVEHOOK | MUTT_FCCHOOK | MUTT_MESSAGEHOOK | MUTT_REPLYHOOK))
{
if ((pat = mutt_pattern_comp (pattern.data,
(data & (MUTT_SENDHOOK | MUTT_SEND2HOOK | MUTT_FCCHOOK)) ? 0 : MUTT_FULL_MSG,
err)) == NULL)
goto error;
}
else
{
/* Hooks not allowing full patterns: Check syntax of regexp */
rx = safe_malloc (sizeof (regex_t));
#ifdef MUTT_CRYPTHOOK
if ((rc = REGCOMP (rx, NONULL(pattern.data), ((data & (MUTT_CRYPTHOOK|MUTT_CHARSETHOOK|MUTT_ICONVHOOK)) ? REG_ICASE : 0))) != 0)
#else
if ((rc = REGCOMP (rx, NONULL(pattern.data), (data & (MUTT_CHARSETHOOK|MUTT_ICONVHOOK)) ? REG_ICASE : 0)) != 0)
#endif /* MUTT_CRYPTHOOK */
{
regerror (rc, rx, err->data, err->dsize);
FREE (&rx);
goto error;
}
}
if (ptr)
{
ptr->next = safe_calloc (1, sizeof (HOOK));
ptr = ptr->next;
}
else
Hooks = ptr = safe_calloc (1, sizeof (HOOK));
ptr->type = data;
ptr->command = command.data;
ptr->pattern = pat;
ptr->rx.pattern = pattern.data;
ptr->rx.rx = rx;
ptr->rx.not = not;
return 0;
error:
FREE (&pattern.data);
FREE (&command.data);
return (-1);
}
示例9: DocWndConvertText
static void DocWndConvertText(char *in, int in_size, char *out, int out_size)
{
char *buffer = (char *)safe_malloc(sizeof(char)*out_size);
int buffer_size = out_size;
int i=0, j=0;
int nl = 0;
// Convert Return Code CR, LF -> CR+LF ,
// Control Code -> ^? (^@, ^A, ^B, ...).
// stage1:
for(;;){
if(i>=in_size || j>=buffer_size-1)
goto stage1_end;
if(nl==13){
if(in[i]==13){
if(j>=buffer_size-2)
goto stage1_end;
buffer[j++] = 13;
buffer[j++] = 10;
i++;
nl = 13;
continue;
}
if(in[i]==10){
if(j>=buffer_size-2)
goto stage1_end;
buffer[j++] = 13;
buffer[j++] = 10;
i++;
nl = 0;
continue;
}
if(j>=buffer_size-2)
goto stage1_end;
buffer[j++] = 13;
buffer[j++] = 10;
if(in[i]>=0 && in[i]<=0x1f && in[i]!='\t'){
if(j>=buffer_size-2)
goto stage1_end;
buffer[j++] = '^';
buffer[j++] = ControlCode[in[i]];
} else {
if(j>=buffer_size-1)
goto stage1_end;
buffer[j++] = in[i];
}
i++;
nl = 0;
continue;
}
if(nl==10){
if(in[i]==13||in[i]==10){
if(j>=buffer_size-2)
goto stage1_end;
buffer[j++] = 13;
buffer[j++] = 10;
nl = in[i];
i++;
continue;
}
if(j>=buffer_size-2)
goto stage1_end;
buffer[j++] = 13;
buffer[j++] = 10;
if(in[i]>=0 && in[i]<=0x1f && in[i]!='\t'){
if(j>=buffer_size-2)
goto stage1_end;
buffer[j++] = '^';
buffer[j++] = ControlCode[in[i]];
} else {
if(j>=buffer_size-1)
goto stage1_end;
buffer[j++] = in[i];
}
i++;
nl = 0;
continue;
}
if(in[i]==13||in[i]==10){
nl = in[i];
i++;
continue;
}
if(in[i]>=0 && in[i]<=0x1f && in[i]!='\t'){
if(j>=buffer_size-2)
goto stage1_end;
buffer[j++] = '^';
buffer[j++] = ControlCode[in[i]];
} else {
if(j>=buffer_size-1)
goto stage1_end;
buffer[j++] = in[i];
}
i++;
nl = 0;
continue;
}
stage1_end:
buffer[j] = '\0';
// Convert KANJI Code.
//.........这里部分代码省略.........
示例10: zfs_callback
/*
* Called for each dataset. If the object is of an appropriate type,
* add it to the avl tree and recurse over any children as necessary.
*/
static int
zfs_callback(zfs_handle_t *zhp, void *data)
{
callback_data_t *cb = data;
boolean_t should_close = B_TRUE;
boolean_t include_snaps = zfs_include_snapshots(zhp, cb);
boolean_t include_bmarks = (cb->cb_types & ZFS_TYPE_BOOKMARK);
if ((zfs_get_type(zhp) & cb->cb_types) ||
((zfs_get_type(zhp) == ZFS_TYPE_SNAPSHOT) && include_snaps)) {
uu_avl_index_t idx;
zfs_node_t *node = safe_malloc(sizeof (zfs_node_t));
node->zn_handle = zhp;
uu_avl_node_init(node, &node->zn_avlnode, avl_pool);
if (uu_avl_find(cb->cb_avl, node, cb->cb_sortcol,
&idx) == NULL) {
if (cb->cb_proplist) {
if ((*cb->cb_proplist) &&
!(*cb->cb_proplist)->pl_all)
zfs_prune_proplist(zhp,
cb->cb_props_table);
if (zfs_expand_proplist(zhp, cb->cb_proplist,
(cb->cb_flags & ZFS_ITER_RECVD_PROPS),
(cb->cb_flags & ZFS_ITER_LITERAL_PROPS))
!= 0) {
free(node);
return (-1);
}
}
uu_avl_insert(cb->cb_avl, node, idx);
should_close = B_FALSE;
} else {
free(node);
}
}
/*
* Recurse if necessary.
*/
if (cb->cb_flags & ZFS_ITER_RECURSE &&
((cb->cb_flags & ZFS_ITER_DEPTH_LIMIT) == 0 ||
cb->cb_depth < cb->cb_depth_limit)) {
cb->cb_depth++;
/*
* If we are not looking for filesystems, we don't need to
* recurse into filesystems when we are at our depth limit.
*/
if ((cb->cb_depth < cb->cb_depth_limit ||
(cb->cb_flags & ZFS_ITER_DEPTH_LIMIT) == 0 ||
(cb->cb_types &
(ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME))) &&
zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) {
(void) zfs_iter_filesystems(zhp, zfs_callback, data);
}
if (((zfs_get_type(zhp) & (ZFS_TYPE_SNAPSHOT |
ZFS_TYPE_BOOKMARK)) == 0) && include_snaps) {
(void) zfs_iter_snapshots(zhp,
(cb->cb_flags & ZFS_ITER_SIMPLE) != 0,
zfs_callback, data, 0, 0);
}
if (((zfs_get_type(zhp) & (ZFS_TYPE_SNAPSHOT |
ZFS_TYPE_BOOKMARK)) == 0) && include_bmarks) {
(void) zfs_iter_bookmarks(zhp, zfs_callback, data);
}
cb->cb_depth--;
}
if (should_close)
zfs_close(zhp);
return (0);
}
示例11: main
int main(int argc, char *argv[])
{
/* Define the options specific to the DNS protocol. */
struct option long_options[] =
{
{"host", required_argument, 0, 0},
{"port", required_argument, 0, 0},
{0, 0, 0, 0} /* End */
};
char c;
int option_index;
const char *option_name;
options = safe_malloc(sizeof(options_t));
srand(time(NULL));
/* Set up some default options. */
options->s = -1;
options->host = DEFAULT_HOST;
options->port = DEFAULT_PORT;
options->buffer = buffer_create(BO_BIG_ENDIAN);
options->group = select_group_create();
options->session = session_create(options->group, tcpcat_send, options, 65535);
/* Parse the command line options. */
opterr = 0;
while((c = getopt_long_only(argc, argv, "", long_options, &option_index)) != EOF)
{
switch(c)
{
case 0:
option_name = long_options[option_index].name;
if(!strcmp(option_name, "host"))
{
options->host = optarg;
}
else if(!strcmp(option_name, "port"))
{
options->port = atoi(optarg);
}
else
{
LOG_FATAL("Unknown option: %s\n", option_name);
exit(1);
/* TODO: Usage */
}
break;
case '?':
default:
/* Do nothing; we expect some unknown arguments. */
break;
}
}
/* Tell the user what's going on */
LOG_INFO("Host: %s\n", options->host);
LOG_INFO("Port: %d\n", options->port);
atexit(cleanup);
/* Add the timeout function */
select_set_timeout(options->group, timeout, (void*)options);
while(TRUE)
select_group_do_select(options->group, 1000);
return 0;
}
示例12: while
static ADDRESS *mutt_expand_aliases_r (ADDRESS *a, LIST **expn)
{
ADDRESS *head = NULL, *last = NULL, *t, *w;
LIST *u;
char i;
const char *fqdn;
while (a)
{
if (!a->group && !a->personal && a->mailbox && strchr (a->mailbox, '@') == NULL)
{
t = mutt_lookup_alias (a->mailbox);
if (t)
{
i = 0;
for (u = *expn; u; u = u->next)
{
if (mutt_strcmp (a->mailbox, u->data) == 0) /* alias already found */
{
dprint (1, (debugfile, "mutt_expand_aliases_r(): loop in alias found for '%s'\n", a->mailbox));
i = 1;
break;
}
}
if (!i)
{
u = safe_malloc (sizeof (LIST));
u->data = safe_strdup (a->mailbox);
u->next = *expn;
*expn = u;
w = rfc822_cpy_adr (t, 0);
w = mutt_expand_aliases_r (w, expn);
if (head)
last->next = w;
else
head = last = w;
while (last && last->next)
last = last->next;
}
t = a;
a = a->next;
t->next = NULL;
rfc822_free_address (&t);
continue;
}
else
{
struct passwd *pw = getpwnam (a->mailbox);
if (pw)
{
char namebuf[STRING];
mutt_gecos_name (namebuf, sizeof (namebuf), pw);
mutt_str_replace (&a->personal, namebuf);
#ifdef EXACT_ADDRESS
FREE (&a->val);
#endif
}
}
}
if (head)
{
last->next = a;
last = last->next;
}
else
head = last = a;
a = a->next;
last->next = NULL;
}
if (option (OPTUSEDOMAIN) && (fqdn = mutt_fqdn(1)))
{
/* now qualify all local addresses */
rfc822_qualify (head, fqdn);
}
return (head);
}
示例13: initialize_rec_element
rec_element*
initialize_rec_element(rec_element* re,
char type,
u_int size,
void* trans,
rec_confidence conf)
{
if( re != NULL ) {
re->re_type = type;
re->re_conf = conf;
re->re_result.aval = NULL;
switch (type) {
case REC_GESTURE:
if( size > 0 && trans != NULL ) {
re->re_result.gval =
(gesture*)safe_malloc(sizeof(gesture));
memcpy((void*)re->re_result.gval,trans,sizeof(gesture));
}
break;
case REC_ASCII:
case REC_VAR:
case REC_OTHER:
if( size > 0 && trans != NULL ) {
re->re_result.aval =
(char*)safe_malloc((size+1)*sizeof(char));
memcpy((void*)re->re_result.aval,trans,size*sizeof(char));
re->re_result.aval[size] = '\000';
}
break;
case REC_WCHAR:
if( size > 0 && trans != NULL ) {
re->re_result.wval =
(wchar_t*)safe_malloc((size+1)*sizeof(wchar_t));
memcpy((void*)re->re_result.wval,trans,size*sizeof(wchar_t));
re->re_result.wval[size] = '\000';
}
break;
case REC_CORR:
if( size > 0 && trans != NULL ) {
re->re_result.rcval =
(rec_correlation*)safe_malloc(sizeof(rec_correlation));
memcpy((void*)re->re_result.rcval,
trans,
sizeof(rec_correlation));
}
break;
default:
return(NULL);
}
}
return(re);
}
示例14: make_rec_info
static rec_info* make_rec_info(char* directory,char* name,char** subset)
{
int i,len;
rec_info* ri;
char* locale;
ri = (rec_info*)safe_malloc(sizeof(rec_info));
ri->ri_locale = NULL;
ri->ri_name = NULL;
ri->ri_subset = NULL;
/*Get locale*/
if( (locale = getenv(LANG)) == NULL ) {
locale = strdup(REC_DEFAULT_LOCALE);
}
if( (ri->ri_locale = strdup(locale)) == NULL ) {
delete_rec_info(ri);
return(NULL);
}
/*Get shared library pathname.*/
/*
* if( (ri->ri_name = shared_library_name(directory,locale,name)) == NULL ) {
* delete_rec_info(ri);
* return(NULL);
* }
*/
/*Initialize the subset information.*/
if( subset != NULL ) {
/*Count the subset strings.*/
for( len = 1; subset[len] != NULL; len++ ) ;
/*Copy the subset strings.*/
ri->ri_subset = (char**)safe_malloc((len +1)*sizeof(char*));
for( i = 0; i < len; i++ ) {
if( subset[i] != NULL ) {
if( (ri->ri_subset[i] = strdup(subset[i])) == NULL ) {
delete_rec_info(ri);
return(NULL);
}
} else {
ri->ri_subset[i] = subset[i];
}
}
ri->ri_subset[i] = NULL;
} else {
ri->ri_subset = NULL;
}
return(ri);
}
示例15: sizeof
struct irec *find_all_interfaces(struct iname *names,
struct iname *addrs,
int port)
{
/* this code is adapted from Stevens, page 434. It finally
destroyed my faith in the C/unix API */
int len = 100 * sizeof(struct ifreq);
int lastlen = 0;
char *buf, *ptr;
struct ifconf ifc;
struct irec *ret = NULL;
int fd = socket(PF_INET, SOCK_DGRAM, 0);
if (fd == -1)
die("cannot create socket to enumerate interfaces: %s", NULL);
while (1)
{
buf = safe_malloc(len);
ifc.ifc_len = len;
ifc.ifc_buf = buf;
if (ioctl(fd, SIOCGIFCONF, &ifc) < 0)
{
if (errno != EINVAL || lastlen != 0)
die("ioctl error while enumerating interfaces: %s", NULL);
}
else
{
if (ifc.ifc_len == lastlen)
break; /* got a big enough buffer now */
lastlen = ifc.ifc_len;
}
len += 10* sizeof(struct ifreq);
safe_free(buf);
}
for (ptr = buf; ptr < buf + ifc.ifc_len; )
{
struct ifreq *ifr = (struct ifreq *) ptr;
union mysockaddr addr;
#ifdef HAVE_SOCKADDR_SA_LEN
ptr += ifr->ifr_addr.sa_len + IF_NAMESIZE;
#else
ptr += sizeof(struct ifreq);
#endif
/* copy address since getting flags overwrites */
if (ifr->ifr_addr.sa_family == AF_INET)
{
addr.in = *((struct sockaddr_in *) &ifr->ifr_addr);
addr.in.sin_port = htons(port);
if (ioctl(fd, SIOCGIFFLAGS, ifr) < 0)
die ("ioctl error getting interface flags: %s", NULL);
ret = add_iface(ret, ifr->ifr_flags, ifr->ifr_name, &addr,
names, addrs);
}
#ifdef HAVE_IPV6
else if (ifr->ifr_addr.sa_family == AF_INET6)
{
#ifdef HAVE_BROKEN_SOCKADDR_IN6
addr.in6 = *((struct my_sockaddr_in6 *) &ifr->ifr_addr);
#else
addr.in6 = *((struct sockaddr_in6 *) &ifr->ifr_addr);
#endif
addr.in6.sin6_port = htons(port);
addr.in6.sin6_flowinfo = htonl(0);
if (ioctl(fd, SIOCGIFFLAGS, ifr) < 0)
die("ioctl error getting interface flags: %s", NULL);
ret = add_iface(ret, ifr->ifr_flags, ifr->ifr_name, &addr,
names, addrs);
}
#endif /* IPV6 */
}
safe_free(buf);
close(fd);
#if defined(HAVE_LINUX_IPV6_PROC) && defined(HAVE_IPV6)
/* IPv6 addresses don't seem to work with SIOCGIFCONF. Barf */
/* This code snarfed from net-tools 1.60 and certainly linux specific, though
it shouldn't break on other Unices, and their SIOGIFCONF might work. */
{
FILE *f = fopen(IP6INTERFACES, "r");
if (f)
{
union mysockaddr addr;
unsigned int plen, scope, flags, if_idx;
char devname[20], addrstring[32];
while (fscanf(f, "%32s %02x %02x %02x %02x %20s\n",
addrstring, &if_idx, &plen, &scope, &flags, devname) != EOF)
{
int i;
unsigned char *addr6p = (unsigned char *) &addr.in6.sin6_addr;
//.........这里部分代码省略.........