本文整理汇总了C++中c_strdup函数的典型用法代码示例。如果您正苦于以下问题:C++ c_strdup函数的具体用法?C++ c_strdup怎么用?C++ c_strdup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了c_strdup函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: http_url_set_password
void
http_url_set_password(struct http_url *url, const char *string) {
c_free(url->password);
url->password = NULL;
if (string)
url->password = c_strdup(string);
}
开发者ID:galdor,项目名称:libhttp,代码行数:8,代码来源:url.c
示例2: http_url_set_user
void
http_url_set_user(struct http_url *url, const char *string) {
c_free(url->user);
url->user = NULL;
if (string)
url->user = c_strdup(string);
}
开发者ID:galdor,项目名称:libhttp,代码行数:8,代码来源:url.c
示例3: http_url_set_scheme
void
http_url_set_scheme(struct http_url *url, const char *string) {
c_free(url->scheme);
url->scheme = NULL;
if (string)
url->scheme = c_strdup(string);
}
开发者ID:galdor,项目名称:libhttp,代码行数:8,代码来源:url.c
示例4: http_url_clone
struct http_url *
http_url_clone(const struct http_url *url) {
struct http_url *new_url;
new_url = http_url_new();
if (url->scheme)
new_url->scheme = c_strdup(url->scheme);
if (url->user)
new_url->user = c_strdup(url->user);
if (url->password)
new_url->password = c_strdup(url->password);
if (url->host)
new_url->host = c_strdup(url->host);
if (url->port)
new_url->port = c_strdup(url->port);
new_url->port_number = url->port_number;
if (url->path)
new_url->path = c_strdup(url->path);
if (url->query)
new_url->query = c_strdup(url->query);
if (url->fragment)
new_url->fragment = c_strdup(url->fragment);
if (url->query_parameters) {
struct c_vector *parameters;
parameters = c_vector_new(sizeof(struct http_query_parameter));
for (size_t i = 0; i < c_vector_length(url->query_parameters); i++) {
struct http_query_parameter *parameter;
struct http_query_parameter new_parameter;
parameter = c_vector_entry(url->query_parameters, i);
http_query_parameter_init(&new_parameter);
new_parameter.name = c_strdup(parameter->name);
new_parameter.value = c_strdup(parameter->value);
c_vector_append(parameters, &new_parameter);
}
new_url->query_parameters = parameters;
}
return new_url;
}
开发者ID:galdor,项目名称:libhttp,代码行数:46,代码来源:url.c
示例5: setup_toplevel_dir
static void setup_toplevel_dir( void **state ) {
char basepath[255];
strcpy( basepath, "tXXXXXX");
assert_int_equal( c_tmpname(basepath), 0 );
printf("Using top testing dir %s\n", basepath);
assert_int_equal( test_mkdir( basepath ), 0 );
*state = (void*) c_strdup(basepath);
}
开发者ID:valarauco,项目名称:galletica,代码行数:9,代码来源:ocmod_test.c
示例6: fill_stat_cache
static void fill_stat_cache( csync_vio_file_stat_t *lfs ) {
if( _stat_cache.name ) SAFE_FREE(_stat_cache.name);
if( _stat_cache.etag ) SAFE_FREE(_stat_cache.etag );
if( !lfs) return;
_stat_cache.name = c_strdup(lfs->name);
_stat_cache.mtime = lfs->mtime;
_stat_cache.fields = lfs->fields;
_stat_cache.type = lfs->type;
_stat_cache.size = lfs->size;
csync_vio_file_stat_set_file_id(&_stat_cache, lfs->file_id);
if( lfs->etag ) {
_stat_cache.etag = c_strdup(lfs->etag);
}
}
开发者ID:liusijiang,项目名称:mirall,代码行数:18,代码来源:csync_owncloud.c
示例7: csync_vio_file_stat_copy
csync_vio_file_stat_t* csync_vio_file_stat_copy(csync_vio_file_stat_t *file_stat) {
csync_vio_file_stat_t *file_stat_cpy = csync_vio_file_stat_new();
memcpy(file_stat_cpy, file_stat, sizeof(csync_vio_file_stat_t));
if (file_stat_cpy->fields & CSYNC_VIO_FILE_STAT_FIELDS_ETAG) {
file_stat_cpy->etag = c_strdup(file_stat_cpy->etag);
}
if (file_stat_cpy->directDownloadCookies) {
file_stat_cpy->directDownloadCookies = c_strdup(file_stat_cpy->directDownloadCookies);
}
if (file_stat_cpy->directDownloadUrl) {
file_stat_cpy->directDownloadUrl = c_strdup(file_stat_cpy->directDownloadUrl);
}
if (file_stat_cpy->checksumHeader) {
file_stat_cpy->checksumHeader = c_strdup(file_stat_cpy->checksumHeader);
}
file_stat_cpy->name = c_strdup(file_stat_cpy->name);
return file_stat_cpy;
}
开发者ID:jturcotte,项目名称:owncloud-client,代码行数:18,代码来源:csync_vio_file_stat.c
示例8: START_TEST
END_TEST
START_TEST (check_c_strdup_nomem)
{
const char *str = "test";
char *tdup = NULL;
tdup = c_strdup(str);
fail_unless(tdup == NULL, NULL);
}
开发者ID:MarkusLitz,项目名称:csync,代码行数:10,代码来源:check_std_c_alloc.c
示例9: sqlite3_mprintf
/* caller must free the memory */
csync_file_stat_t *csync_statedb_get_stat_by_inode(sqlite3 *db,
uint64_t inode) {
csync_file_stat_t *st = NULL;
c_strlist_t *result = NULL;
char *stmt = NULL;
size_t len = 0;
if (!inode) {
return NULL;
}
stmt = sqlite3_mprintf("SELECT * FROM metadata WHERE inode='%lld'",
(long long signed int) inode);
if (stmt == NULL) {
return NULL;
}
result = csync_statedb_query(db, stmt);
sqlite3_free(stmt);
if (result == NULL) {
return NULL;
}
if (result->count <= 6) {
c_strlist_destroy(result);
return NULL;
}
/* phash, pathlen, path, inode, uid, gid, mode, modtime */
len = strlen(result->vector[2]);
st = c_malloc(sizeof(csync_file_stat_t) + len + 1);
if (st == NULL) {
c_strlist_destroy(result);
return NULL;
}
/* clear the whole structure */
ZERO_STRUCTP(st);
st->phash = atoll(result->vector[0]);
st->pathlen = atoi(result->vector[1]);
memcpy(st->path, (len ? result->vector[2] : ""), len + 1);
st->inode = atoll(result->vector[3]);
st->uid = atoi(result->vector[4]);
st->gid = atoi(result->vector[5]);
st->mode = atoi(result->vector[6]);
st->modtime = strtoul(result->vector[7], NULL, 10);
st->type = atoi(result->vector[8]);
if( result->vector[9] )
st->etag = c_strdup(result->vector[9]);
csync_vio_set_file_id( st->file_id, result->vector[10]);
c_strlist_destroy(result);
return st;
}
开发者ID:Gnostech,项目名称:mirall,代码行数:56,代码来源:csync_statedb.c
示例10: START_TEST
END_TEST
START_TEST (check_c_strreplace)
{
char *str = c_strdup("/home/%(USER)");
str = c_strreplace(str, "%(USER)", "csync");
fail_unless(strcmp(str, "/home/csync") == 0, NULL);
SAFE_FREE(str);
}
开发者ID:MarkusLitz,项目名称:csync,代码行数:11,代码来源:check_std_c_str.c
示例11: _csync_file_stat_from_metadata_table
// This funciton parses a line from the metadata table into the given csync_file_stat
// structure which it is also allocating.
// Note that this function calls laso sqlite3_step to actually get the info from db and
// returns the sqlite return type.
static int _csync_file_stat_from_metadata_table( csync_file_stat_t **st, sqlite3_stmt *stmt )
{
int rc = SQLITE_ERROR;
int column_count;
int len;
if( ! stmt ) {
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "Fatal: Statement is NULL.");
return SQLITE_ERROR;
}
column_count = sqlite3_column_count(stmt);
rc = sqlite3_step(stmt);
if( rc == SQLITE_ROW ) {
if(column_count > 7) {
const char *name;
/* phash, pathlen, path, inode, uid, gid, mode, modtime */
len = sqlite3_column_int(stmt, 1);
*st = c_malloc(sizeof(csync_file_stat_t) + len + 1);
if (*st == NULL) {
return SQLITE_NOMEM;
}
/* clear the whole structure */
ZERO_STRUCTP(*st);
/* The query suceeded so use the phash we pass to the function. */
(*st)->phash = sqlite3_column_int64(stmt, 0);
(*st)->pathlen = sqlite3_column_int(stmt, 1);
name = (const char*) sqlite3_column_text(stmt, 2);
memcpy((*st)->path, (len ? name : ""), len + 1);
(*st)->inode = sqlite3_column_int64(stmt,3);
(*st)->uid = sqlite3_column_int(stmt, 4);
(*st)->gid = sqlite3_column_int(stmt, 5);
(*st)->mode = sqlite3_column_int(stmt, 6);
(*st)->modtime = strtoul((char*)sqlite3_column_text(stmt, 7), NULL, 10);
if(*st && column_count > 8 ) {
(*st)->type = sqlite3_column_int(stmt, 8);
}
if(column_count > 9 && sqlite3_column_text(stmt, 9)) {
(*st)->etag = c_strdup( (char*) sqlite3_column_text(stmt, 9) );
}
if(column_count > 10 && sqlite3_column_text(stmt,10)) {
csync_vio_set_file_id((*st)->file_id, (char*) sqlite3_column_text(stmt, 10));
}
}
}
return rc;
}
开发者ID:DeepDiver1975,项目名称:mirall,代码行数:58,代码来源:csync_statedb.c
示例12: resourceToFileStat
/*
* helper: convert a resource struct to file_stat struct.
*/
void resourceToFileStat(csync_vio_file_stat_t *lfs, struct resource *res )
{
ZERO_STRUCTP(lfs);
lfs->name = c_strdup( res->name );
lfs->fields = CSYNC_VIO_FILE_STAT_FIELDS_NONE;
if( res->type == resr_normal ) {
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_TYPE;
lfs->type = CSYNC_VIO_FILE_TYPE_REGULAR;
} else if( res->type == resr_collection ) {
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_TYPE;
lfs->type = CSYNC_VIO_FILE_TYPE_DIRECTORY;
} else {
DEBUG_WEBDAV("ERROR: Unknown resource type %d", res->type);
}
// FIXME Those are defaults, we'll have to use the real ownCloud WebDAV permissions soon
lfs->mode = _stat_perms( lfs->type );
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_PERMISSIONS;
lfs->mtime = res->modtime;
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MTIME;
lfs->size = res->size;
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_SIZE;
if( res->md5 ) {
lfs->etag = c_strdup(res->md5);
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_ETAG;
}
csync_vio_file_stat_set_file_id(lfs, res->file_id);
if (res->directDownloadUrl) {
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_DIRECTDOWNLOADURL;
lfs->directDownloadUrl = c_strdup(res->directDownloadUrl);
}
if (res->directDownloadCookies) {
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_DIRECTDOWNLOADCOOKIES;
lfs->directDownloadCookies = c_strdup(res->directDownloadCookies);
}
}
开发者ID:etiess,项目名称:mirall,代码行数:44,代码来源:csync_owncloud_util.c
示例13: resourceToFileStat
/*
* helper: convert a resource struct to file_stat struct.
*/
void resourceToFileStat(csync_vio_file_stat_t *lfs, struct resource *res )
{
ZERO_STRUCTP(lfs);
lfs->name = c_strdup( res->name );
lfs->fields = CSYNC_VIO_FILE_STAT_FIELDS_NONE;
if( res->type == resr_normal ) {
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_TYPE;
lfs->type = CSYNC_VIO_FILE_TYPE_REGULAR;
} else if( res->type == resr_collection ) {
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_TYPE;
lfs->type = CSYNC_VIO_FILE_TYPE_DIRECTORY;
} else {
DEBUG_WEBDAV("ERROR: Unknown resource type %d", res->type);
}
lfs->mtime = res->modtime;
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MTIME;
lfs->size = res->size;
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_SIZE;
if( res->md5 ) {
lfs->etag = c_strdup(res->md5);
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_ETAG;
}
csync_vio_file_stat_set_file_id(lfs, res->file_id);
if (res->directDownloadUrl) {
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_DIRECTDOWNLOADURL;
lfs->directDownloadUrl = c_strdup(res->directDownloadUrl);
}
if (res->directDownloadCookies) {
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_DIRECTDOWNLOADCOOKIES;
lfs->directDownloadCookies = c_strdup(res->directDownloadCookies);
}
if (strlen(res->remotePerm) > 0) {
lfs->fields = CSYNC_VIO_FILE_STAT_FIELDS_PERM;
strncpy(lfs->remotePerm, res->remotePerm, sizeof(lfs->remotePerm));
}
}
开发者ID:abzahri,项目名称:lcsshare-win,代码行数:44,代码来源:csync_owncloud_util.c
示例14: check_c_strdup
static void check_c_strdup(void **state)
{
const char *str = "test";
char *tdup = NULL;
(void) state; /* unused */
tdup = c_strdup(str);
assert_string_equal(tdup, str);
free(tdup);
}
开发者ID:Gnostech,项目名称:mirall,代码行数:12,代码来源:check_std_c_alloc.c
示例15: c_strdup
/*
* dirname - parse directory component.
*/
char *c_dirname (const char *path) {
char *newbuf = NULL;
unsigned int len;
if (path == NULL || *path == '\0') {
return c_strdup(".");
}
len = strlen(path);
/* Remove trailing slashes */
while(len > 0 && path[len - 1] == '/') --len;
/* We have only slashes */
if (len == 0) {
return c_strdup("/");
}
/* goto next slash */
while(len > 0 && path[len - 1] != '/') --len;
if (len == 0) {
return c_strdup(".");
} else if (len == 1) {
return c_strdup("/");
}
/* Remove slashes again */
while(len > 0 && path[len - 1] == '/') --len;
newbuf = c_malloc(len + 1);
if (newbuf == NULL) {
return NULL;
}
strncpy(newbuf, path, len);
newbuf[len] = '\0';
return newbuf;
}
开发者ID:Azelphur,项目名称:mirall,代码行数:43,代码来源:c_path.c
示例16: csync_vio_file_stat_new
csync_vio_file_stat_t *csync_vio_convert_file_stat(csync_file_stat_t *st) {
csync_vio_file_stat_t *vfs = NULL;
if (st == NULL) {
return NULL;
}
vfs = csync_vio_file_stat_new();
if (vfs == NULL) {
return NULL;
}
vfs->acl = NULL;
if (st->pathlen > 0) {
vfs->name = c_strdup(st->path);
}
vfs->uid = st->uid;
vfs->gid = st->gid;
vfs->atime = 0;
vfs->mtime = st->modtime;
vfs->ctime = 0;
vfs->size = st->size;
vfs->blksize = 0; /* Depricated. */
vfs->blkcount = 0;
vfs->mode = st->mode;
vfs->device = 0;
vfs->inode = st->inode;
vfs->nlink = st->nlink;
/* fields. */
vfs->fields = CSYNC_VIO_FILE_STAT_FIELDS_TYPE
+ CSYNC_VIO_FILE_STAT_FIELDS_PERMISSIONS
+ CSYNC_VIO_FILE_STAT_FIELDS_INODE
+ CSYNC_VIO_FILE_STAT_FIELDS_LINK_COUNT
+ CSYNC_VIO_FILE_STAT_FIELDS_SIZE
+ CSYNC_VIO_FILE_STAT_FIELDS_MTIME
+ CSYNC_VIO_FILE_STAT_FIELDS_UID
+ CSYNC_VIO_FILE_STAT_FIELDS_GID;
if (st->type == CSYNC_FTW_TYPE_DIR)
vfs->type = CSYNC_VIO_FILE_TYPE_DIRECTORY;
else if (st->type == CSYNC_FTW_TYPE_FILE)
vfs->type = CSYNC_VIO_FILE_TYPE_REGULAR;
else if (st->type == CSYNC_FTW_TYPE_SLINK)
vfs->type = CSYNC_VIO_FILE_TYPE_SYMBOLIC_LINK;
else
vfs->type = CSYNC_VIO_FILE_TYPE_UNKNOWN;
return vfs;
}
开发者ID:Absolight,项目名称:mirall,代码行数:52,代码来源:csync_util.c
示例17: setup
static void setup(void **state) {
CSYNC *csync;
int rc;
rc = csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2");
assert_int_equal(rc, 0);
free(csync->options.config_dir);
csync->options.config_dir = c_strdup("/tmp/check_csync1/");
assert_non_null(csync->options.config_dir);
*state = csync;
}
开发者ID:alexta901,项目名称:mirall,代码行数:13,代码来源:check_csync_exclude.c
示例18: c_malloc
/*
* helper: convert a resource struct to file_stat struct.
*/
csync_vio_file_stat_t *resourceToFileStat( struct resource *res )
{
csync_vio_file_stat_t *lfs = NULL;
if( ! res ) {
return NULL;
}
lfs = c_malloc(sizeof(csync_vio_file_stat_t));
if (lfs == NULL) {
errno = ENOMEM;
return NULL;
}
lfs->name = c_strdup( res->name );
lfs->fields = CSYNC_VIO_FILE_STAT_FIELDS_NONE;
if( res->type == resr_normal ) {
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_TYPE;
lfs->type = CSYNC_VIO_FILE_TYPE_REGULAR;
} else if( res->type == resr_collection ) {
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_TYPE;
lfs->type = CSYNC_VIO_FILE_TYPE_DIRECTORY;
} else {
DEBUG_WEBDAV("ERROR: Unknown resource type %d", res->type);
}
lfs->mtime = res->modtime;
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MTIME;
lfs->size = res->size;
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_SIZE;
if( res->md5 ) {
lfs->etag = c_strdup(res->md5);
}
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_ETAG;
csync_vio_file_stat_set_file_id(lfs, res->file_id);
return lfs;
}
开发者ID:DeepDiver1975,项目名称:mirall,代码行数:42,代码来源:csync_owncloud_util.c
示例19: resource_dup
struct resource* resource_dup(struct resource* o) {
struct resource *r = c_malloc (sizeof( struct resource ));
ZERO_STRUCTP(r);
r->uri = c_strdup(o->uri);
r->name = c_strdup(o->name);
r->type = o->type;
r->size = o->size;
r->modtime = o->modtime;
if( o->md5 ) {
r->md5 = c_strdup(o->md5);
}
if (o->directDownloadUrl) {
r->directDownloadUrl = c_strdup(o->directDownloadUrl);
}
if (o->directDownloadCookies) {
r->directDownloadCookies = c_strdup(o->directDownloadCookies);
}
r->next = o->next;
csync_vio_set_file_id(r->file_id, o->file_id);
return r;
}
开发者ID:etiess,项目名称:mirall,代码行数:23,代码来源:csync_owncloud_util.c
示例20: csync_set_config_dir
int csync_set_config_dir(CSYNC *ctx, const char *path) {
if (ctx == NULL || path == NULL) {
return -1;
}
SAFE_FREE(ctx->options.config_dir);
ctx->options.config_dir = c_strdup(path);
if (ctx->options.config_dir == NULL) {
ctx->status_code = CSYNC_STATUS_MEMORY_ERROR;
return -1;
}
return 0;
}
开发者ID:aduchate,项目名称:mirall,代码行数:14,代码来源:csync.c
注:本文中的c_strdup函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论