本文整理汇总了C++中s_strdup函数的典型用法代码示例。如果您正苦于以下问题:C++ s_strdup函数的具体用法?C++ s_strdup怎么用?C++ s_strdup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了s_strdup函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: qq_account_insert_index_node
void qq_account_insert_index_node(qq_account* ac, const LwqqBuddy* b,
const LwqqGroup* g)
{
#if QQ_USE_FAST_INDEX
if (!ac || (!b && !g))
return;
index_node* node = s_malloc0(sizeof(*node));
int type = b ? NODE_IS_BUDDY : NODE_IS_GROUP;
node->type = type;
if (type == NODE_IS_BUDDY) {
node->node = b;
const LwqqBuddy* buddy = b;
g_hash_table_insert(ac->fast_index.uin_index, s_strdup(buddy->uin), node);
if (buddy->qqnumber)
g_hash_table_insert(ac->fast_index.qqnum_index,
s_strdup(buddy->qqnumber), node);
} else {
node->node = g;
const LwqqGroup* group = g;
g_hash_table_insert(ac->fast_index.uin_index, s_strdup(group->gid), node);
if (group->account)
g_hash_table_insert(ac->fast_index.qqnum_index,
s_strdup(group->account), node);
}
#endif
}
示例2: device_new
struct device_t *
device_new (struct udev_device *dev)
{
struct device_t *device;
const char *dev_type;
const char *dev_idtype;
device = malloc(sizeof(struct device_t));
device->udev = dev;
device->devnode = s_strdup(udev_device_get_devnode(dev));
device->filesystem = s_strdup(udev_device_get_property_value(dev, "ID_FS_TYPE"));
dev_type = udev_device_get_devtype(dev);
dev_idtype = udev_device_get_property_value(dev, "ID_TYPE");
device->type = DEVICE_UNK;
if (!device->filesystem) {
device_destroy(device);
return NULL;
}
if (!strcmp(dev_type, "partition")||
!strcmp(dev_type, "disk") ||
!strcmp(dev_idtype, "floppy")) {
device->type = DEVICE_VOLUME;
} else if (!strcmp(dev_idtype, "cd")) {
device->type = DEVICE_CD;
}
if (device->type == DEVICE_UNK) {
device_destroy(device);
return NULL;
}
device->has_media = device_has_media(device);
device->fstab_entry = fstab_search(g_fstab, device);
device->mountpoint = NULL;
if (device->has_media) {
if (device->fstab_entry) {
device->mountpoint = s_strdup(device->fstab_entry->path);
} else {
device->mountpoint = device_create_mountpoint(device);
}
}
device->mounted = device_is_mounted(device->devnode);
if (!device_register(device)) {
device_destroy(device);
return NULL;
}
return device;
}
示例3: mkpath
int mkpath(const char *s, mode_t mode){
char *q, *r = NULL, *path = NULL, *up = NULL;
int rv;
rv = -1;
if (strcmp(s, ".") == 0 || strcmp(s, "/") == 0)
return (0);
path=s_strdup(s);
q = s_strdup(s);
r = s_dirname(q);
up = s_strdup(r);
if ((mkpath(up, mode) == -1) && (errno != EEXIST))
goto out;
if ((mkdir(path, mode) == -1) && (errno != EEXIST))
rv = -1;
else
rv = 0;
out:
if (up != NULL)
free(up);
free(q);
free(path);
free(r);
return (rv);
}
示例4: fstab_parse
int
fstab_parse (struct fstab_t *fstab)
{
FILE *f;
struct mntent *mntent;
struct fstab_node_t *node;
struct fstab_node_t *last;
f = setmntent(FSTAB_PATH, "r");
if (!f)
return 0;
while ((mntent = getmntent(f))) {
node = malloc(sizeof(struct fstab_node_t));
node->next = NULL;
node->node = s_strdup(mntent->mnt_fsname);
node->path = s_strdup(mntent->mnt_dir);
node->type = s_strdup(mntent->mnt_type);
node->opts = s_strdup(mntent->mnt_opts);
if (!fstab->head) {
fstab->head = node;
} else {
last = fstab->head;
while (last->next) {
last = last->next;
}
last->next = node;
}
}
endmntent(f);
return 1;
}
示例5: s_strdup
char *s_basename(char *path)
{
char *tmpstr;
char *rdir;
char *retstr;
tmpstr = s_strdup(path);
rdir = basename(tmpstr);
retstr = s_strdup(rdir);
free(tmpstr);
return retstr;
}
示例6: insert
void insert(int intarget)
{
size_t
nmemb;
PATTERN_
*p;
char
**p2;
str2pattern ();
nmemb = n_patterns;
p = lfind (buffer2, patterns, &nmemb, sizeof (PATTERN_), lfindpat);
if (! p) {
if (n_patterns == max_patterns) {
max_patterns += 32;
patterns = (PATTERN_ *) s_realloc (patterns, max_patterns * sizeof (PATTERN_));
}
patterns [n_patterns].s = s_strdup (buffer2);
patterns [n_patterns].n_forms = 0;
patterns [n_patterns].max_forms = 0;
patterns [n_patterns].i = 0;
patterns [n_patterns].o = 0;
patterns [n_patterns].used = 0;
patterns [n_patterns].rejected = 0;
patterns [n_patterns].forms = NULL;
p = &(patterns [n_patterns]);
n_patterns++;
}
if (intarget)
p->i++;
else
p->o++;
if (p->i + p->o >= minvar)
p->used = 1;
p2 = NULL;
if (p->n_forms > 0) {
nmemb = p->n_forms;
p2 = lfind (buffer, p->forms, &nmemb, sizeof (char *), searchcmp);
}
if (! p2) {
if (p->n_forms == p->max_forms) {
p->max_forms += 32;
p->forms = (char **) s_realloc (p->forms, p->max_forms * sizeof (char *));
}
p->forms[p->n_forms] = s_strdup (buffer);
p->n_forms++;
}
}
示例7: append_str
/*
* Append the string pointed to by "str" to the string pointed to by "orig"
* adding the delimeter "delim" in between.
*
* Return a pointer to the new string or NULL, if we were passed a bad string.
*/
static char *
append_str(char *orig, char *str, char *delim)
{
char *newstr;
int len;
if ((str == NULL) || (delim == NULL))
return (NULL);
if ((orig == NULL) || (*orig == NULL)) {
/*
* Return a pointer to a copy of the path so a caller can
* always rely upon being able to free() a returned pointer.
*/
return (s_strdup(str));
}
len = strlen(orig) + strlen(str) + strlen(delim) + 1;
if ((newstr = malloc(len)) == NULL) {
bam_error(NO_MEM, len);
bam_exit(1);
}
(void) snprintf(newstr, len, "%s%s%s", orig, delim, str);
return (newstr);
}
示例8: add_logcat
/*
| Adds a logging category
|
| Returns true if OK.
*/
static bool
add_logcat( const char *name, int priority )
{
struct logcat *lc;
if( !strcmp( "all", name ) )
{
settings.log_level = 99;
return true;
}
if( !strcmp( "scarce", name ) )
{
settings.log_level = LOG_WARNING;
return true;
}
// categories must start with a capital letter.
if( name[ 0 ] < 'A' || name[ 0 ] > 'Z' )
{ return false; }
if( !logcats[ name[ 0 ]- 'A' ] )
{
// an empty capital letter
lc = logcats[name[0]-'A'] = s_calloc(2, sizeof(struct logcat));
}
else
{
// length of letter list
int ll = 0;
// counts list length
for( lc = logcats[name[0]-'A']; lc->name; lc++ )
{ ll++; }
// enlarges list
logcats[ name[ 0 ] - 'A'] =
s_realloc(
logcats[ name[ 0 ]-'A' ],
( ll + 2 ) * sizeof( struct logcat )
);
// goes to the list end
for( lc = logcats[ name[ 0 ] - 'A']; lc->name; lc++ )
{
if( !strcmp( name, lc->name ) )
{
// already there
return true;
}
}
}
lc->name = s_strdup( name );
lc->priority = priority;
// terminates the list
lc[ 1 ].name = NULL;
return true;
}
示例9: S_CLR_ERR
S_API SObject *SObjectSetString(const char *s, s_erc *error)
{
SString *self;
S_CLR_ERR(error);
if (s == NULL)
{
S_CTX_ERR(error, S_ARGERROR,
"SObjectSetString",
"Argument \"s\" is NULL");
return NULL;
}
self = S_NEW(SString, error);
if (S_CHK_ERR(error, S_FAILURE,
"SObjectSetString",
"Failed to create new SString object"))
return NULL;
self->s = s_strdup(s, error);
if (S_CHK_ERR(error, S_CONTERR,
"SObjectSetString",
"Failed to copy string"))
{
S_DELETE(self, "SObjectSetString", error);
return NULL;
}
return S_OBJECT(self);
}
示例10: S_CLR_ERR
/**
* Insert a string after given string list element. Return reference
* to inserted string element.
*/
S_API const s_str_list_element *s_str_list_insert_after(s_str_list_element *self,
const char *string, s_erc *error)
{
const s_str_list_element *el;
char *new_string;
S_CLR_ERR(error);
if ((self == NULL) || (string == NULL))
return NULL;
new_string = s_strdup(string, error);
if (S_CHK_ERR(error, S_CONTERR,
"s_str_list_insert_after",
"Call to \"s_strdup\" failed"))
return NULL;
el = s_list_insert_after(self, new_string, error);
if (S_CHK_ERR(error, S_CONTERR,
"s_str_list_insert_after",
"Call to \"s_list_insert_after\" failed"))
{
S_FREE(new_string);
return NULL;
}
return el;
}
示例11: s_str_list_element_replace
/**
* Replace the string list element's string. The replaced string is
* freed.
*/
S_API void s_str_list_element_replace(s_str_list_element *self, const char *string,
s_erc *error)
{
char *replaced;
char *new_string;
S_CLR_ERR(error);
if ((self == NULL) || (string == NULL))
return;
new_string = s_strdup(string, error);
if (S_CHK_ERR(error, S_CONTERR,
"s_str_list_element_replace",
"Call to \"s_strdup\" failed"))
return;
replaced = s_list_element_replace(self, new_string, error);
if (S_CHK_ERR(error, S_CONTERR,
"s_str_list_element_replace",
"Call to \"s_list_element_replace\" failed"))
{
S_FREE(new_string);
return;
}
S_FREE(replaced);
}
示例12: modify_path
/*
* Replace the substring "old_str" in a path with the substring "new_str"
*
* Return a pointer to the modified string.
*/
static char *
modify_path(char *path, char *old_str, char *new_str)
{
char *newpath;
char *pc;
int len;
/*
* Return a pointer to a copy of the path so a caller can always rely
* upon being able to free() a returned pointer.
*/
if ((pc = strstr(path, old_str)) == NULL)
return (s_strdup(path));
/*
* Allocate space for duplicate of path with name changes and
* NULL terminating byte
*/
len = strlen(path) - strlen(old_str) + strlen(new_str) + 1;
if ((newpath = malloc(len)) == NULL) {
bam_error(NO_MEM, len);
bam_exit(1);
}
(void) strlcpy(newpath, path, (pc - path) + 1);
pc += strlen(old_str);
(void) strcat(newpath, new_str);
(void) strcat(newpath, pc);
return (newpath);
}
示例13: qq_account_new
qq_account* qq_account_new(PurpleAccount* account)
{
qq_account* ac = g_malloc0(sizeof(qq_account));
ac->account = account;
ac->magic = QQ_MAGIC;
ac->flag = 0;
//this is auto increment sized array . so don't worry about it.
const char* username = purple_account_get_username(account);
const char* password = purple_account_get_password(account);
ac->qq = lwqq_client_new(username,password);
ac->js = lwqq_js_init();
ac->sys_log = purple_log_new(PURPLE_LOG_SYSTEM, "system", account, NULL, time(NULL), NULL);
ac->font.family = s_strdup("宋体");
ac->font.size = 12;
ac->font.style = 0;
//lwqq_async_set(ac->qq,1);
#if QQ_USE_FAST_INDEX
ac->qq->find_buddy_by_uin = find_buddy_by_uin;
ac->qq->find_buddy_by_qqnumber = find_buddy_by_qqnumber;
ac->fast_index.uin_index = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,g_free);
ac->fast_index.qqnum_index = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,NULL);
#endif
ac->qq->dispatch = qq_dispatch;
return ac;
}
示例14: upload_file_init
static void upload_file_init(PurpleXfer* xfer)
{
void** data = xfer->data;
qq_account* ac = data[0];
LwqqClient* lc = ac->qq;
LwqqMsgOffFile* file = s_malloc0(sizeof(*file));
file->from = s_strdup(lc->myself->uin);
file->to = s_strdup(purple_xfer_get_remote_user(xfer));
file->name = s_strdup(purple_xfer_get_local_filename(xfer));
xfer->start_time = time(NULL);
data[1] = file;
data[2] = xfer;
//lwqq_async_add_event_listener(
background_upload_file(lc,file,file_trans_on_progress,xfer);
//send_file,data);
}
示例15: check_add_file
void check_add_file(char *filename) {
const char *bn;
if (filename == NULL || *filename == '\0')
return;
if (access(filename, R_OK) < 0) {
warn("could not open file: %s", filename);
return;
}
if (fileidx == filecnt) {
filecnt *= 2;
files = (fileinfo_t*) s_realloc(files, filecnt * sizeof(fileinfo_t));
}
if (*filename != '/') {
files[fileidx].path = absolute_path(filename);
if (files[fileidx].path == NULL) {
warn("could not get absolute path of file: %s\n", filename);
return;
}
}
files[fileidx].loaded = false;
files[fileidx].name = s_strdup(filename);
if (*filename == '/')
files[fileidx].path = files[fileidx].name;
if ((bn = strrchr(files[fileidx].name , '/')) != NULL && bn[1] != '\0')
files[fileidx].base = ++bn;
else
files[fileidx].base = files[fileidx].name;
fileidx++;
}