Skip to content

Commit

Permalink
Implement STRDUP
Browse files Browse the repository at this point in the history
To use strdup function in kernel space, we implement STRDUP and
use it in gdev_cuda.c.
  • Loading branch information
Constellation committed Nov 19, 2013
1 parent 360d0cb commit b94e726
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cuda/driver/gdev_cuda.c
Expand Up @@ -433,7 +433,7 @@ static struct CUfunc_st* malloc_func_if_necessary(struct CUmod_st *mod, const ch
}
init_kernel(&func->kernel);
init_raw_func(&func->raw_func);
func->raw_func.name = strdup(name);
func->raw_func.name = STRDUP(name);

/* insert this function to the module's function list. */
gdev_list_init(&func->list_entry, func);
Expand Down
16 changes: 15 additions & 1 deletion util/gdev_platform.h
Expand Up @@ -90,8 +90,22 @@
#define IOWRITE32(val, addr) *(uint32_t *)(addr) = val
#endif

#ifdef __KERNEL__ /* OS functions related to File IO */
#ifdef __KERNEL__ /* OS functions */
static inline char* STRDUP(const char *str) {
size_t len;
char *buf;
if (!str) {
return NULL;
}
len = strlen(str) + 1;
buf = MALLOC(len);
if (buf) {
memcpy(buf, str, len);
}
return buf;
}
#else /* user-space functions */
#define STRDUP strdup
#endif

#endif /* __GDEV_PLATFORM_H__ */

0 comments on commit b94e726

Please sign in to comment.