本文整理汇总了C++中s_strdup函数的典型用法代码示例。如果您正苦于以下问题:C++ s_strdup函数的具体用法?C++ s_strdup怎么用?C++ s_strdup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了s_strdup函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:iOpen,项目名称:pidgin-lwqq,代码行数:26,代码来源:qq_types.c
示例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;
}
开发者ID:vodik,项目名称:ldm,代码行数:60,代码来源:ldm.c
示例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);
}
开发者ID:chineseneo,项目名称:lessfs,代码行数:26,代码来源:lib_safe.c
示例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;
}
开发者ID:vodik,项目名称:ldm,代码行数:33,代码来源:ldm.c
示例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;
}
开发者ID:chineseneo,项目名称:lessfs,代码行数:11,代码来源:lib_safe.c
示例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++;
}
}
开发者ID:pebbe,项目名称:Gabmap,代码行数:53,代码来源:determinants1.c
示例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);
}
开发者ID:CoryXie,项目名称:opensolaris,代码行数:32,代码来源:bootadm_hyper.c
示例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;
}
开发者ID:dreiss,项目名称:lsyncd,代码行数:65,代码来源:lsyncd.c
示例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);
}
开发者ID:Oghma,项目名称:speect,代码行数:32,代码来源:primitives.c
示例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;
}
开发者ID:Cyofanni,项目名称:speect,代码行数:32,代码来源:str_list.c
示例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);
}
开发者ID:Cyofanni,项目名称:speect,代码行数:32,代码来源:str_list.c
示例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);
}
开发者ID:CoryXie,项目名称:opensolaris,代码行数:37,代码来源:bootadm_hyper.c
示例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;
}
开发者ID:5rather,项目名称:pidgin-lwqq,代码行数:27,代码来源:qq_types.c
示例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);
}
开发者ID:lawm,项目名称:pidgin-lwqq,代码行数:16,代码来源:ft.c
示例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++;
}
开发者ID:dimatura,项目名称:sxiv,代码行数:32,代码来源:main.c
示例16: str_list_prepend
struct str_list_* str_list_prepend(struct str_list_* list,const char* str)
{
struct str_list_* ret = s_malloc0(sizeof(struct str_list_));
ret->str = s_strdup(str);
ret->next = list;
return ret;
}
开发者ID:btbxbob,项目名称:lwqq,代码行数:7,代码来源:internal.c
示例17: device_create_mountpoint
char *
device_create_mountpoint (struct device_t *device)
{
char tmp[256];
char *c;
strcpy(tmp, "/media/");
if (udev_device_get_property_value(device->udev, "ID_FS_LABEL") != NULL)
strcat(tmp, udev_device_get_property_value(device->udev, "ID_FS_LABEL"));
else if (udev_device_get_property_value(device->udev, "ID_FS_UUID") != NULL)
strcat(tmp, udev_device_get_property_value(device->udev, "ID_FS_UUID"));
else if (udev_device_get_property_value(device->udev, "ID_SERIAL") != NULL)
strcat(tmp, udev_device_get_property_value(device->udev, "ID_SERIAL"));
/* Replace the whitespaces */
for (c = (char*)&tmp; *c; c++) {
if (*c == ' ')
*c = '_';
}
/* It can't fail as every disc should have at least the serial */
return s_strdup(tmp);
}
开发者ID:vodik,项目名称:ldm,代码行数:25,代码来源:ldm.c
示例18: strdata_from_buf
static ssize_t
strdata_from_buf(uint8_t *buf, size_t nbytes, size_t n, ...)
{
const char **cur;
uint16_t magic;
ssize_t avail;
size_t slen;
va_list ap;
#define BUF_WALK(bytes) \
do { \
buf += bytes; \
avail -= bytes; \
\
if (avail < 0) \
return -1; \
} while (0)
#define CONSUME_BYTES(nb) \
({ \
uint8_t *obuf = buf; \
BUF_WALK(nb); \
obuf; \
})
#define CONSUME_TYPE(type) \
*((type *) ({ \
CONSUME_BYTES(sizeof(type)); \
}))
avail = nbytes;
va_start(ap, n);
while (n--) {
cur = va_arg(ap, const char **);
*cur = NULL;
slen = CONSUME_TYPE(size_t);
*cur = (char *) CONSUME_BYTES(slen);
magic = CONSUME_TYPE(uint16_t);
if (magic != IPC_MAGIC) {
*cur = NULL;
return -1;
}
/* null-terminate the string (this is a little hack) */
*(buf - 2) = '\0';
*cur = s_strdup(*cur);
}
va_end(ap);
#undef CONSUME_TYPE
#undef CONSUME_BYTES
#undef BUF_WALK
return nbytes - avail;
}
开发者ID:artfwo,项目名称:serialosc,代码行数:59,代码来源:ipc.c
示例19: memset
struct ir_ncode *defineCode(char *key, char *val, struct ir_ncode *code)
{
memset(code, 0, sizeof(*code));
code->name = s_strdup(key);
code->code = s_strtocode(val);
LOGPRINTF(3, " %-20s 0x%016llX", code->name, code->code);
return (code);
}
开发者ID:matzrh,项目名称:lirc,代码行数:8,代码来源:config_file.c
示例20: openread
void openread (char const *s)
{
filename = s_strdup (s);
lineno = 0;
fp = fopen (filename, "r");
if (! fp)
errit ("Opening file \"%s\": %s", filename, strerror (errno));
}
开发者ID:pebbe,项目名称:Gabmap,代码行数:8,代码来源:determinants1.c
注:本文中的s_strdup函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论