本文整理汇总了C++中safe_strdup函数的典型用法代码示例。如果您正苦于以下问题:C++ safe_strdup函数的具体用法?C++ safe_strdup怎么用?C++ safe_strdup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了safe_strdup函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: StrArrayAdd
void StrArrayAdd(StrArray* arr, const char* str)
{
char** old_table;
if ((arr == NULL) || (arr->Table == NULL))
return;
if (arr->Index == arr->Max) {
arr->Max *= 2;
old_table = arr->Table;
arr->Table = (char**)realloc(arr->Table, arr->Max*sizeof(char*));
if (arr->Table == NULL) {
free(old_table);
uprintf("Could not reallocate string array\n");
return;
}
}
arr->Table[arr->Index] = safe_strdup(str);
if (arr->Table[arr->Index++] == NULL) {
uprintf("Could not store string in array\n");
}
}
开发者ID:aienkel,项目名称:rufus,代码行数:20,代码来源:stdfn.c
示例2: fatal_error
/* You must free() this yourself. */
const vm_char *factor_vm::default_image_path()
{
vm_char full_path[MAX_UNICODE_PATH];
vm_char *ptr;
vm_char temp_path[MAX_UNICODE_PATH];
if(!GetModuleFileName(NULL, full_path, MAX_UNICODE_PATH))
fatal_error("GetModuleFileName() failed", 0);
if((ptr = wcsrchr(full_path, '.')))
*ptr = 0;
wcsncpy(temp_path, full_path, MAX_UNICODE_PATH - 1);
size_t full_path_len = wcslen(full_path);
if (full_path_len < MAX_UNICODE_PATH - 1)
wcsncat(temp_path, L".image", MAX_UNICODE_PATH - full_path_len - 1);
temp_path[MAX_UNICODE_PATH - 1] = 0;
return safe_strdup(temp_path);
}
开发者ID:8byte-jose,项目名称:factor,代码行数:21,代码来源:os-windows.cpp
示例3: lirc_channel_join
void lirc_channel_join(struct LIRCServer_struct* server,
struct LIRCClientData_struct* client,
char *channel)
{
char temp[MAX_IRC_MESSAGE_SIZE];
dlnode_t* client_node;
LIRCChannelData* c =
(LIRCChannelData*)find_element(server->channel_list,
channel, lirc_channel_cmp);
if (c == NULL)
{
/* The channel doesn't exist in the list so we
* will need to create one */
c = lirc_channel_new_metadata();
c->name = safe_strdup(channel);
insert_at_front(server->channel_list, c, sizeof(c));
}
/* Add this client to the list */
insert_at_front(c->client_list, client,
sizeof(client));
/* Add a weak reference to the joined channels list of the client */
insert_at_front(client->channel_list, c, sizeof(c));
/* Send a response message to all connected clients inside the
* channel indicating that a join was made */
client_node = c->client_list->head;
sprintf(temp, ":%s!~%[email protected] JOIN %s\r\n", client->nick, client->user,
channel);
while (client_node != NULL)
{
struct LIRCClientData_struct *client_node_data =
(struct LIRCClientData_struct *)client_node->data;
send(client_node_data->socket, temp, strlen(temp), 0);
client_node = client_node->next;
}
}
开发者ID:TripleChocPi,项目名称:LIRC,代码行数:41,代码来源:channel.c
示例4: iptables_fw_find_mention
// add by lijg, 2013-05-30, Find keyword @mention in firewall rule table = @table and chain = @chain
// return : 0 - not found, 1 - found it .
int iptables_fw_find_mention(
const char * table,
const char * chain,
const char * mention
) {
FILE *p = NULL;
char *command = NULL;
char line[MAX_BUF];
char *victim = safe_strdup(mention);
int found = 0;
// 1.1 @victim="WiFiDog_br-lan_Trusted"
iptables_insert_gateway_id(&victim);
debug(LOG_DEBUG, "Attempting to find all mention of %s from %s.%s", victim, table, chain);
safe_asprintf(&command, "iptables -t %s -L %s -n --line-numbers -v", table, chain);
iptables_insert_gateway_id(&command);
//1.2 执行命令 iptables -t mangle -L PREROUTING -n --line-numbers -v, 逐行输出链中规则
if ((p = popen(command, "r"))) {
/* Skip first 2 lines */
while (!feof(p) && fgetc(p) != '\n');
while (!feof(p) && fgetc(p) != '\n');
/* Loop over entries */
while (fgets(line, sizeof(line), p)) { // 匹配链中每条规则
/* Look for victim */
if (strstr(line, victim)) { // 根据客户端IP地址进行匹配
found = 1;
break;
}
}
pclose(p);
}
free(command);
free(victim);
return (found);
}
开发者ID:canyuxin,项目名称:openwrt-mt7620,代码行数:43,代码来源:fw_iptables.c
示例5: w32g_add_playlist1
static int w32g_add_playlist1(char *filename, int uniq, int refine)
{
PlayListEntry *entry;
char *title;
struct midi_file_info *info;
if(uniq)
{
int i;
for(i = 0; i < playlist.nfiles; i++)
if(pathcmp(filename, playlist.list[i].filename, 0) == 0)
return 0;
}
title = get_midi_title(filename);
info = get_midi_file_info(filename, 1);
if(refine && info->format < 0)
return 0;
if(playlist.allocated == 0)
{
playlist.allocated = 32;
playlist.list = (PlayListEntry *)safe_malloc(playlist.allocated *
sizeof(PlayListEntry));
}
else if(playlist.nfiles == playlist.allocated)
{
playlist.allocated *= 2;
playlist.list = (PlayListEntry *)safe_realloc(playlist.list,
playlist.allocated *
sizeof(PlayListEntry));
}
entry = &playlist.list[playlist.nfiles];
entry->filename = safe_strdup(filename);
entry->title = title;
entry->info = info;
playlist.nfiles++;
w32g_shuffle_playlist_reset(1);
return 1;
}
开发者ID:Distrotech,项目名称:TiMidity,代码行数:41,代码来源:w32g_playlist.c
示例6: get_iface_ip
char *
get_iface_ip(const char ifname[])
{
char addrbuf[INET6_ADDRSTRLEN+1];
const struct ifaddrs *cur;
struct ifaddrs *addrs;
s_config *config;
if(getifaddrs(&addrs) < 0) {
debug(LOG_ERR, "getifaddrs(): %s", strerror(errno));
return NULL;
}
config = config_get_config();
/* Set default address */
sprintf(addrbuf, config->ip6 ? "::" : "0.0.0.0");
/* Iterate all interfaces */
cur = addrs;
while(cur != NULL) {
if( (cur->ifa_addr != NULL) && (strcmp( cur->ifa_name, ifname ) == 0) ) {
if(config->ip6 && cur->ifa_addr->sa_family == AF_INET6) {
inet_ntop(AF_INET6, &((struct sockaddr_in6 *)cur->ifa_addr)->sin6_addr, addrbuf, sizeof(addrbuf));
break;
}
if(!config->ip6 && cur->ifa_addr->sa_family == AF_INET) {
inet_ntop(AF_INET, &((struct sockaddr_in *)cur->ifa_addr)->sin_addr, addrbuf, sizeof(addrbuf));
break;
}
}
cur = cur->ifa_next;
}
freeifaddrs(addrs);
return safe_strdup(addrbuf);
}
开发者ID:VonRosenchild,项目名称:nodogsplash,代码行数:41,代码来源:util.c
示例7: sym_bi_gets
/*---------------------------------------------------------------------------
* Purpose: Return the string value of a builtin symbol.
*
* Return: Copy of the string value or NULL
*
* Programmer: Robb Matzke
* Friday, June 2, 2000
*
* Modifications:
*---------------------------------------------------------------------------
*/
char *
sym_bi_gets(const char *name)
{
char fullname[1024], *retval;
obj_t var, val;
/* Add built-in prefix */
if (*name!='$') {
fullname[0] = '$';
strcpy(fullname+1, name);
name = fullname;
}
var = obj_new(C_SYM, name);
val = sym_vboundp(var);
var = obj_dest(var);
retval = safe_strdup(obj_name(val));
obj_dest(val);
return retval;
}
开发者ID:drhansj,项目名称:polymec-dev,代码行数:32,代码来源:sym.c
示例8: guestfs_impl_get_sockdir
/* Note this actually calculates the sockdir, so it never returns NULL. */
char *
guestfs_impl_get_sockdir (guestfs_h *g)
{
const char *str;
uid_t euid = geteuid ();
if (euid == 0) {
/* Use /tmp exclusively for root, as otherwise qemu (running as
* qemu.qemu when launched by libvirt) will not be able to access
* the directory.
*/
str = "/tmp";
} else {
if (g->env_runtimedir)
str = g->env_runtimedir;
else
str = "/tmp";
}
return safe_strdup (g, str);
}
开发者ID:AlphaStaxLLC,项目名称:libguestfs,代码行数:22,代码来源:tmpdirs.c
示例9: guestfs__inspect_get_type
char *
guestfs__inspect_get_type (guestfs_h *g, const char *root)
{
struct inspect_fs *fs = guestfs___search_for_root (g, root);
if (!fs)
return NULL;
char *ret;
switch (fs->type) {
case OS_TYPE_DOS:
ret = safe_strdup (g, "dos");
break;
case OS_TYPE_FREEBSD:
ret = safe_strdup (g, "freebsd");
break;
case OS_TYPE_HURD:
ret = safe_strdup (g, "hurd");
break;
case OS_TYPE_LINUX:
ret = safe_strdup (g, "linux");
break;
case OS_TYPE_NETBSD:
ret = safe_strdup (g, "netbsd");
break;
case OS_TYPE_OPENBSD:
ret = safe_strdup (g, "openbsd");
break;
case OS_TYPE_WINDOWS:
ret = safe_strdup (g, "windows");
break;
case OS_TYPE_UNKNOWN:
default:
ret = safe_strdup (g, "unknown");
break;
}
return ret;
}
开发者ID:yumingfei,项目名称:libguestfs,代码行数:38,代码来源:inspect.c
示例10: c_locale_vsnprintf
int
c_locale_vsnprintf (char *str, size_t size, const char *format, va_list ap)
{
#ifdef _MSC_VER
# define vsnprintf _vsnprintf
#endif
int result;
char *locale;
locale = safe_strdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, "C");
result = vsnprintf(str, size, format, ap);
setlocale(LC_ALL, locale);
free(locale);
return result;
}
开发者ID:0u812,项目名称:roadrunner-backup,代码行数:21,代码来源:util.c
示例11: iptables_compile
/**
* @internal
* Compiles a struct definition of a firewall rule into a valid iptables
* command.
* @arg table Table containing the chain.
* @arg chain Chain that the command will be (-A)ppended to.
* @arg rule Definition of a rule into a struct, from conf.c.
*/
static char *
iptables_compile(const char * table, const char *chain, const t_firewall_rule *rule)
{
char command[MAX_BUF],
*mode;
memset(command, 0, MAX_BUF);
switch (rule->target){
case TARGET_DROP:
mode = safe_strdup("DROP");
break;
case TARGET_REJECT:
mode = safe_strdup("REJECT");
break;
case TARGET_ACCEPT:
mode = safe_strdup("ACCEPT");
break;
case TARGET_LOG:
mode = safe_strdup("LOG");
break;
case TARGET_ULOG:
mode = safe_strdup("ULOG");
break;
}
snprintf(command, sizeof(command), "-t %s -A %s ",table, chain);
if (rule->mask != NULL) {
snprintf((command + strlen(command)), (sizeof(command) -
strlen(command)), "-d %s ", rule->mask);
}
if (rule->protocol != NULL) {
snprintf((command + strlen(command)), (sizeof(command) -
strlen(command)), "-p %s ", rule->protocol);
}
if (rule->port != NULL) {
snprintf((command + strlen(command)), (sizeof(command) -
strlen(command)), "--dport %s ", rule->port);
}
snprintf((command + strlen(command)), (sizeof(command) -
strlen(command)), "-j %s", mode);
free(mode);
/* XXX The buffer command, an automatic variable, will get cleaned
* off of the stack when we return, so we strdup() it. */
return(safe_strdup(command));
}
开发者ID:aircross,项目名称:mydog,代码行数:56,代码来源:fw_iptables.c
示例12: guestfs__set_attach_method
int
guestfs__set_attach_method (guestfs_h *g, const char *method)
{
if (STREQ (method, "appliance")) {
g->attach_method = ATTACH_METHOD_APPLIANCE;
free (g->attach_method_arg);
g->attach_method_arg = NULL;
}
else if (STRPREFIX (method, "unix:") && strlen (method) > 5) {
g->attach_method = ATTACH_METHOD_UNIX;
free (g->attach_method_arg);
g->attach_method_arg = safe_strdup (g, method + 5);
/* Note that we don't check the path exists until launch is called. */
}
else {
error (g, "invalid attach method: %s", method);
return -1;
}
return 0;
}
开发者ID:mdbooth,项目名称:libguestfs,代码行数:21,代码来源:guestfs.c
示例13: guestfs_set_private
void
guestfs_set_private (guestfs_h *g, const char *key, void *data)
{
if (g->pda == NULL) {
g->pda = hash_initialize (16, NULL, hasher, comparator, freer);
if (g->pda == NULL)
g->abort_cb ();
}
struct pda_entry *new_entry = safe_malloc (g, sizeof *new_entry);
new_entry->key = safe_strdup (g, key);
new_entry->data = data;
struct pda_entry *old_entry = hash_delete (g->pda, new_entry);
freer (old_entry);
struct pda_entry *entry = hash_insert (g->pda, new_entry);
if (entry == NULL)
g->abort_cb ();
assert (entry == new_entry);
}
开发者ID:mdbooth,项目名称:libguestfs,代码行数:21,代码来源:guestfs.c
示例14: guestfs_impl_set_identifier
int
guestfs_impl_set_identifier (guestfs_h *g, const char *identifier)
{
size_t i, len;
/* Check the identifier contains only permitted characters. */
len = strlen (identifier);
for (i = 0; i < len; ++i) {
char c = identifier[i];
if (!c_isalnum (c) && c != '_' && c != '-') {
error (g, _("identifier must contain only alphanumeric characters, underscore or minus sign"));
return -1;
}
}
free (g->identifier);
g->identifier = safe_strdup (g, identifier);
return 0;
}
开发者ID:myyyy,项目名称:libguestfs,代码行数:21,代码来源:handle.c
示例15: update_tags
static int update_tags(notmuch_message_t *msg, const char *tags)
{
char *tag = NULL, *end = NULL, *p;
char *buf = safe_strdup(tags);
if (!buf)
return -1;
notmuch_message_freeze(msg);
for (p = buf; p && *p; p++) {
if (!tag && isspace(*p))
continue;
if (!tag)
tag = p; /* begin of the tag */
if (*p == ',' || *p == ' ')
end = p; /* terminate the tag */
else if (*(p + 1) == '\0')
end = p + 1; /* end of optstr */
if (!tag || !end)
continue;
if (tag >= end)
break;
*end = '\0';
if (*tag == '-') {
dprint(1, (debugfile, "nm: remove tag: '%s'\n", tag + 1));
notmuch_message_remove_tag(msg, tag + 1);
} else {
dprint(1, (debugfile, "nm: add tag: '%s'\n", *tag == '+' ? tag + 1 : tag));
notmuch_message_add_tag(msg, *tag == '+' ? tag + 1 : tag);
}
end = tag = NULL;
}
notmuch_message_thaw(msg);
FREE(&buf);
return 0;
}
开发者ID:ceyusa,项目名称:mutt-kz,代码行数:40,代码来源:mutt_notmuch.c
示例16: main
int main (int argc, char **argv)
{
int i;
char *p;
struct utsname utsname;
/* determine the system's host name */
uname (&utsname);
if (!(Hostname = safe_strdup (utsname.nodename)))
return DL_EX_ERROR;
if ((p = strchr (Hostname, '.')))
*p = '\0';
/* parse the command line options. */
DotlockFlags = 0;
while ((i = getopt (argc, argv, "dtfur:")) != EOF)
{
switch (i)
{
/* actions, mutually exclusive */
case 't': check_flags (DotlockFlags); DotlockFlags |= DL_FL_TRY; break;
case 'd': check_flags (DotlockFlags); DotlockFlags |= DL_FL_UNLINK; break;
case 'u': check_flags (DotlockFlags); DotlockFlags |= DL_FL_UNLOCK; break;
/* other flags */
case 'f': DotlockFlags |= DL_FL_FORCE; break;
case 'r': DotlockFlags |= DL_FL_RETRY; Retry = atoi (optarg); break;
default: usage (argv[0]);
}
}
if (optind == argc || Retry < 0)
usage (argv[0]);
return dotlock_dispatch (argv[optind], -1);
}
开发者ID:AndreySV,项目名称:lbdb,代码行数:40,代码来源:dotlock.c
示例17: url_dumpfile
static char *
url_dumpfile(URL url, const char *ext)
{
char filename[1024];
char *tmpdir;
int fd;
FILE *fp;
int n;
char buff[BUFSIZ];
#ifdef TMPDIR
tmpdir = TMPDIR;
#else
tmpdir = getenv("TMPDIR");
#endif
if(tmpdir == NULL || strlen(tmpdir) == 0)
tmpdir = PATH_STRING "tmp" PATH_STRING;
if(IS_PATH_SEP(tmpdir[strlen(tmpdir) - 1]))
snprintf(filename, sizeof(filename), "%sXXXXXX.%s", tmpdir, ext);
else
snprintf(filename, sizeof(filename), "%s" PATH_STRING "XXXXXX.%s",
tmpdir, ext);
fd = tmdy_mkstemp(filename);
if (fd == -1)
return NULL;
if ((fp = fdopen(fd, "w")) == NULL) {
close(fd);
unlink(filename);
return NULL;
}
while((n = url_read(url, buff, sizeof(buff))) > 0)
fwrite(buff, 1, n, fp);
fclose(fp);
return safe_strdup(filename);
}
开发者ID:Jberlinsky,项目名称:LittleBands,代码行数:39,代码来源:common.c
示例18: dlt_linuxsll_register
/*
* Function to register ourselves. This function is always called, regardless
* of what DLT types are being used, so it shouldn't be allocating extra buffers
* or anything like that (use the dlt_linuxsll_init() function below for that).
* Tasks:
* - Create a new plugin struct
* - Fill out the provides/requires bit masks. Note: Only specify which fields are
* actually in the header.
* - Add the plugin to the context's plugin chain
* Returns: TCPEDIT_ERROR | TCPEDIT_OK | TCPEDIT_WARN
*/
int
dlt_linuxsll_register(tcpeditdlt_t *ctx)
{
tcpeditdlt_plugin_t *plugin;
assert(ctx);
/* create a new plugin structure */
plugin = tcpedit_dlt_newplugin();
/* FIXME: set what we provide & require */
plugin->provides += PLUGIN_MASK_PROTO + PLUGIN_MASK_SRCADDR;
plugin->requires += 0;
/* what is our DLT value? */
plugin->dlt = dlt_value;
/* set the prefix name of our plugin. This is also used as the prefix for our options */
plugin->name = safe_strdup(dlt_prefix);
/*
* Point to our functions, note, you need a function for EVERY method.
* Even if it is only an empty stub returning success.
*/
plugin->plugin_init = dlt_linuxsll_init;
plugin->plugin_cleanup = dlt_linuxsll_cleanup;
plugin->plugin_parse_opts = dlt_linuxsll_parse_opts;
plugin->plugin_decode = dlt_linuxsll_decode;
plugin->plugin_encode = dlt_linuxsll_encode;
plugin->plugin_proto = dlt_linuxsll_proto;
plugin->plugin_l2addr_type = dlt_linuxsll_l2addr_type;
plugin->plugin_l2len = dlt_linuxsll_l2len;
plugin->plugin_get_layer3 = dlt_linuxsll_get_layer3;
plugin->plugin_merge_layer3 = dlt_linuxsll_merge_layer3;
plugin->plugin_get_mac = dlt_linuxsll_get_mac;
/* add it to the available plugin list */
return tcpedit_dlt_addplugin(ctx, plugin);
}
开发者ID:GabrielGanne,项目名称:tcpreplay,代码行数:50,代码来源:linuxsll.c
示例19: add_to_allowed_mac_list
/* Add given MAC address to the config's allowed mac list.
* Return 0 on success, nonzero on failure
*/
int add_to_allowed_mac_list(const char possiblemac[])
{
char *mac = NULL;
t_MAC *p = NULL;
/* check for valid format */
if (!check_mac_format(possiblemac)) {
debug(LOG_NOTICE, "[%s] not a valid MAC address to allow", possiblemac);
return -1;
}
/* abort if not using ALLOW mechanism */
if (MAC_ALLOW != config.macmechanism) {
debug(LOG_NOTICE, "Attempt to access allowed MAC list but control mechanism != allow");
return -1;
}
mac = safe_malloc(18);
sscanf(possiblemac, "%17[A-Fa-f0-9:]", mac);
/* See if MAC is already on the list; don't add duplicates */
for (p = config.allowedmaclist; p != NULL; p = p->next) {
if (!strcasecmp(p->mac,mac)) {
debug(LOG_INFO, "MAC address [%s] already on allowed list", mac);
free(mac);
return 1;
}
}
/* Add MAC to head of list */
p = safe_malloc(sizeof(t_MAC));
p->mac = safe_strdup(mac);
p->next = config.allowedmaclist;
config.allowedmaclist = p;
debug(LOG_INFO, "Added MAC address [%s] to allowed list", mac);
free(mac);
return 0;
}
开发者ID:andreyhammer,项目名称:nodogsplash,代码行数:42,代码来源:conf.c
示例20: parse_opt
static error_t parse_opt (int key, char *arg, struct argp_state *state)
{
struct btd_config *config = state->input;
switch (key)
{
case 'q':
btd_decr_log();
break;
case 'v':
btd_incr_log();
break;
case ARGP_KEY_ARG:
config->configpath = safe_strdup(arg);
break;
case ARGP_KEY_END:
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
开发者ID:dopefishh,项目名称:btd,代码行数:22,代码来源:config.c
注:本文中的safe_strdup函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论