本文整理汇总了C++中safestrcpy函数的典型用法代码示例。如果您正苦于以下问题:C++ safestrcpy函数的具体用法?C++ safestrcpy怎么用?C++ safestrcpy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了safestrcpy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UpdatePositionDisplay
void UpdatePositionDisplay( int train_number, int speed, char* pos_node, int pos_offset, int error, int max_error, char* dest_node, int dest_offset, char* state ) {
int tid = -1;
tid = WhoIs( "trainsTAB" );
//check the return value of WhoIs
if( tid < 0 ) {
return;
}
//create the message
struct train_position_output_message msg;
msg.message_type = TRAIN_POSITION_OUTPUT_MESSAGE;
msg.train_nums = train_number;
msg.train_speeds = speed;
safestrcpy( msg.train_pos_node, pos_node, 6 );
msg.train_pos_off = pos_offset;
msg.train_err = error;
msg.train_max_err = max_error;
safestrcpy( msg.train_dest_node, dest_node, 6 );
msg.train_dest_off = dest_offset;
safestrcpy( msg.train_state, state, 6 );
//send the message via courier
CourierSend( tid, (char *)&msg, sizeof (msg) );
}
示例2: userinit
//PAGEBREAK: 32
// Set up first user process.
void
userinit(void)
{
struct proc *p;
extern char _binary_initcode_start[], _binary_initcode_size[];
p = allocproc();
initproc = p;
initproc->uid = 0;
if((p->pgdir = setupkvm()) == 0)
panic("userinit: out of memory?");
inituvm(p->pgdir, _binary_initcode_start, (int)_binary_initcode_size);
p->sz = PGSIZE;
memset(p->tf, 0, sizeof(*p->tf));
p->tf->cs = (SEG_UCODE << 3) | DPL_USER;
p->tf->ds = (SEG_UDATA << 3) | DPL_USER;
p->tf->es = p->tf->ds;
p->tf->ss = p->tf->ds;
p->tf->eflags = FL_IF;
p->tf->esp = PGSIZE;
p->tf->eip = 0; // beginning of initcode.S
safestrcpy(p->name, "initcode", sizeof(p->name));
p->cwd = namei("/");
safestrcpy(p->wdpath, "/\n", 2); //start in the root directory
p->state = RUNNABLE;
}
示例3: dprintf
/**
* sysfs_open_class_device_path: Opens and populates class device
* @path: path to class device.
* returns struct sysfs_class_device with success and NULL with error.
*/
struct sysfs_class_device *sysfs_open_class_device_path(const char *path)
{
struct sysfs_class_device *cdev;
char temp_path[SYSFS_PATH_MAX];
if (!path) {
errno = EINVAL;
return NULL;
}
/*
* Post linux-2.6.14 driver model supports nested classes with
* links to the nested hierarchy at /sys/class/xxx/. Check for
* a link to the actual class device if a directory isn't found
*/
if (sysfs_path_is_dir(path)) {
dprintf("%s: Directory not found, checking for a link\n", path);
if (!sysfs_path_is_link(path)) {
if (sysfs_get_link(path, temp_path, SYSFS_PATH_MAX)) {
dprintf("Error retrieving link at %s\n", path);
return NULL;
}
} else {
dprintf("%s is not a valid class device path\n", path);
return NULL;
}
} else
safestrcpy(temp_path, path);
cdev = alloc_class_device();
if (!cdev) {
dprintf("calloc failed\n");
return NULL;
}
if (sysfs_get_name_from_path(temp_path, cdev->name, SYSFS_NAME_LEN)) {
errno = EINVAL;
dprintf("Error getting class device name\n");
sysfs_close_class_device(cdev);
return NULL;
}
safestrcpy(cdev->path, temp_path);
if (sysfs_remove_trailing_slash(cdev->path)) {
dprintf("Invalid path to class device %s\n", cdev->path);
sysfs_close_class_device(cdev);
return NULL;
}
set_classdev_classname(cdev);
return cdev;
}
示例4: memset
/**
* sysfs_get_bus_devices: gets all devices for bus
* @bus: bus to get devices for
* returns dlist of devices with success and NULL with failure
*/
struct dlist *sysfs_get_bus_devices(struct sysfs_bus *bus)
{
struct sysfs_device *dev;
struct dlist *linklist;
char path[SYSFS_PATH_MAX], devpath[SYSFS_PATH_MAX];
char target[SYSFS_PATH_MAX];
char *curlink;
if (!bus) {
errno = EINVAL;
return NULL;
}
memset(path, 0, SYSFS_PATH_MAX);
safestrcpy(path, bus->path);
safestrcat(path, "/");
safestrcat(path, SYSFS_DEVICES_NAME);
linklist = read_dir_links(path);
if (linklist) {
dlist_for_each_data(linklist, curlink, char) {
if (bus->devices) {
dev = (struct sysfs_device *)
dlist_find_custom(bus->devices,
(void *)curlink, name_equal);
if (dev)
continue;
}
safestrcpy(devpath, path);
safestrcat(devpath, "/");
safestrcat(devpath, curlink);
if (sysfs_get_link(devpath, target, SYSFS_PATH_MAX)) {
dprintf("Error getting link - %s\n", devpath);
continue;
}
dev = sysfs_open_device_path(target);
if (!dev) {
dprintf("Error opening device at %s\n",
target);
continue;
}
if (!bus->devices)
bus->devices = dlist_new_with_delete
(sizeof(struct sysfs_device),
sysfs_close_dev);
dlist_unshift_sorted(bus->devices, dev, sort_list);
}
sysfs_close_list(linklist);
}
return (bus->devices);
}
示例5: memset
/**
* sysfs_open_class: opens specific class and all its devices on system
* returns sysfs_class structure with success or NULL with error.
*/
struct sysfs_class *sysfs_open_class(const char *name)
{
struct sysfs_class *cls = NULL;
char *c, classpath[SYSFS_PATH_MAX];
if (!name) {
errno = EINVAL;
return NULL;
}
memset(classpath, 0, SYSFS_PATH_MAX);
if ((sysfs_get_mnt_path(classpath, SYSFS_PATH_MAX)) != 0) {
dprintf("Sysfs not supported on this system\n");
return NULL;
}
safestrcat(classpath, "/");
if (strcmp(name, SYSFS_BLOCK_NAME) == 0) {
safestrcat(classpath, SYSFS_BLOCK_NAME);
if (!sysfs_path_is_dir(classpath))
goto done;
c = strrchr(classpath, '/');
*(c+1) = '\0';
}
safestrcat(classpath, SYSFS_CLASS_NAME);
safestrcat(classpath, "/");
safestrcat(classpath, name);
done:
if (sysfs_path_is_dir(classpath)) {
dprintf("Class %s not found on the system\n", name);
return NULL;
}
cls = alloc_class();
if (cls == NULL) {
dprintf("calloc failed\n");
return NULL;
}
safestrcpy(cls->name, name);
safestrcpy(cls->path, classpath);
if ((sysfs_remove_trailing_slash(cls->path)) != 0) {
dprintf("Invalid path to class device %s\n", cls->path);
sysfs_close_class(cls);
return NULL;
}
return cls;
}
示例6: safestrcpy
/**
* sysfs_get_bus_driver: Get specific driver on bus using driver name
* @bus: bus to find driver on
* @drvname: name of driver
* returns struct sysfs_driver reference or NULL if not found.
*/
struct sysfs_driver *sysfs_get_bus_driver(struct sysfs_bus *bus,
const char *drvname)
{
struct sysfs_driver *drv;
char drvpath[SYSFS_PATH_MAX];
if (!bus || !drvname) {
errno = EINVAL;
return NULL;
}
if (bus->drivers) {
drv = (struct sysfs_driver *)dlist_find_custom
(bus->drivers, (void *)drvname, name_equal);
if (drv)
return drv;
}
safestrcpy(drvpath, bus->path);
safestrcat(drvpath, "/");
safestrcat(drvpath, SYSFS_DRIVERS_NAME);
safestrcat(drvpath, "/");
safestrcat(drvpath, drvname);
drv = sysfs_open_driver_path(drvpath);
if (!drv) {
dprintf("Error opening driver at %s\n", drvpath);
return NULL;
}
if (!bus->drivers)
bus->drivers = dlist_new_with_delete
(sizeof(struct sysfs_driver),
sysfs_close_drv);
dlist_unshift_sorted(bus->drivers, drv, sort_list);
return drv;
}
示例7: createInternalProcess
// Set up internal proccess for swap managment (inswapper)
void
createInternalProcess(const char *name, void (*entrypoint)())
{
struct proc *p;
extern char _binary_initcode_start[], _binary_initcode_size[];
p = allocproc();
inswapper = p;
if((p->pgdir = setupkvm(kalloc)) == 0)
panic("inswapper: out of memory?");
inituvm(p->pgdir, _binary_initcode_start, (int)_binary_initcode_size);
p->sz = PGSIZE;
memset(p->tf, 0, sizeof(*p->tf));
p->tf->cs = (SEG_UCODE << 3) | DPL_USER;
p->tf->ds = (SEG_UDATA << 3) | DPL_USER;
p->tf->es = p->tf->ds;
p->tf->ss = p->tf->ds;
p->tf->eflags = FL_IF;
p->tf->esp = PGSIZE;
p->tf->eip = 0;
p->context->eip = (uint) entrypoint; // beginning of inswapper
safestrcpy(p->name, name, sizeof(p->name));
p->cwd = namei("/");
// start sleeping until first proccess is created
p->state = SLEEPING;
}
示例8: userinit
//PAGEBREAK: 32
// Set up first user process.
void
userinit(void)
{
struct proc *p;
extern char _binary_initcode_start[], _binary_initcode_size[];
p = allocproc();
initproc = p;
if((p->pgdir = setupkvm()) == 0)
panic("userinit: out of memory?");
inituvm(p->pgdir, _binary_initcode_start, (int)_binary_initcode_size);
p->sz = PGSIZE;
memset(p->tf, 0, sizeof(*p->tf));
p->tf->cs = (SEG_UCODE << 3) | DPL_USER;
p->tf->ds = (SEG_UDATA << 3) | DPL_USER;
p->tf->es = p->tf->ds;
p->tf->ss = p->tf->ds;
p->tf->eflags = FL_IF;
p->tf->esp = PGSIZE;
p->tf->eip = 0; // beginning of initcode.S
safestrcpy(p->name, "initcode", sizeof(p->name));
p->cwd = namei("/");
p->state = RUNNABLE;
#ifndef __ORIGINAL_SCHED__
penqueue(p);
#endif
}
示例9: userinit
// Set up first user process.
void
userinit(void)
{
struct proc *p;
extern uchar _binary_initcode_start[], _binary_initcode_size[];
p = copyproc(0);
p->sz = PAGE;
p->mem = kalloc(p->sz);
p->cwd = namei("/");
memset(p->tf, 0, sizeof(*p->tf));
p->tf->cs = (SEG_UCODE << 3) | DPL_USER;
p->tf->ds = (SEG_UDATA << 3) | DPL_USER;
p->tf->es = p->tf->ds;
p->tf->ss = p->tf->ds;
p->tf->eflags = FL_IF;
p->tf->esp = p->sz;
// Make return address readable; needed for some gcc.
p->tf->esp -= 4;
*(uint*)(p->mem + p->tf->esp) = 0xefefefef;
// On entry to user space, start executing at beginning of initcode.S.
p->tf->eip = 0;
memmove(p->mem, _binary_initcode_start, (int)_binary_initcode_size);
safestrcpy(p->name, "initcode", sizeof(p->name));
#ifdef LOTTERY
p->tickets = INIT_TICKETS;
#endif
p->state = UNUSED;
setstate(p, RUNNABLE);
initproc = p;
}
示例10: userinit
//PAGEBREAK: 32
// Set up first user process.
void
userinit(void)
{
struct proc *p;
extern char _binary_initcode_start[], _binary_initcode_size[];
p = allocproc();
initproc = p;
if((p->pgdir = setupkvm()) == 0)
panic("userinit: out of memory?");
inituvm(p->pgdir, _binary_initcode_start, (int)_binary_initcode_size);
p->sz = PGSIZE;
memset(p->tf, 0, sizeof(*p->tf));
p->tf->cs = (SEG_UCODE << 3) | DPL_USER;
p->tf->ds = (SEG_UDATA << 3) | DPL_USER;
p->tf->es = p->tf->ds;
p->tf->ss = p->tf->ds;
p->tf->eflags = FL_IF;
p->tf->esp = PGSIZE;
p->tf->eip = 0; // beginning of initcode.S
safestrcpy(p->name, "initcode", sizeof(p->name));
p->cwd = namei("/");
p->state = RUNNABLE;
p->next = NULL; // initialize queue next pointer
p->priority = 15; // initialize priority
//****
//cprintf("add in userinit\n");
acquire(&ptable.lock);
addtoq(p);
release(&ptable.lock);
//****
}
示例11: userinit
//PAGEBREAK: 32
// Set up first user process.
void
userinit(void)
{
struct proc *p;
extern char _binary_initcode_start[], _binary_initcode_size[];
p = allocproc();
initproc = p;
if((p->pgdir = setupkvm()) == 0)
panic("userinit: out of memory?");
inituvm(p->pgdir, _binary_initcode_start, (int)_binary_initcode_size);
p->sz = PGSIZE;
memset(p->tf, 0, sizeof(*p->tf));
p->tf->cs = (SEG_UCODE << 3) | DPL_USER;
p->tf->ds = (SEG_UDATA << 3) | DPL_USER;
p->tf->es = p->tf->ds;
p->tf->ss = p->tf->ds;
p->tf->eflags = FL_IF;
p->tf->esp = PGSIZE;
p->tf->eip = 0; // beginning of initcode.S
safestrcpy(p->name, "initcode", sizeof(p->name));
p->cwd = namei("/");
// this assignment to p->state lets other cores
// run this process. the acquire forces the above
// writes to be visible, and the lock is also needed
// because the assignment might not be atomic.
acquire(&ptable.lock);
p->state = RUNNABLE;
release(&ptable.lock);
}
示例12: checkpoint
// Create a new process copying p as the parent.
// Sets up stack to return as if from system call.
static int checkpoint(struct proc *p)
{
// Allocate process.
//if((checkpoint_proc = allocproc()) == 0)
// return -1;
// Copy process state from p.
if((p->pgdir = copyuvm(proc->pgdir, proc->sz)) == 0){
kfree(p->kstack);
p->kstack = 0;
p->state = UNUSED;
return -1;
}
p->sz = proc->sz;
p->parent = proc;
// *p->tf = *proc->tf;
// Clear %eax so that fork returns 0 in the child.
// p->tf->eax = 0;
/*
for(i = 0; i < NOFILE; i++)
if(proc->ofile[i])
p->ofile[i] = filedup(proc->ofile[i]);
p->cwd = idup(proc->cwd);
*/
safestrcpy(p->name, proc->name, sizeof(proc->name));
cprintf("Your process name was: %s\n", p->name);
return 0;
}
示例13: alloc_attribute
/**
* sysfs_open_attribute: creates sysfs_attribute structure
* @path: path to attribute.
* returns sysfs_attribute struct with success and NULL with error.
*/
struct sysfs_attribute *sysfs_open_attribute(const char *path)
{
struct sysfs_attribute *sysattr = NULL;
struct stat fileinfo;
if (path == NULL) {
errno = EINVAL;
return NULL;
}
sysattr = alloc_attribute();
if (sysattr == NULL) {
dprintf("Error allocating attribute at %s\n", path);
return NULL;
}
if (sysfs_get_name_from_path(path, sysattr->name,
SYSFS_NAME_LEN) != 0) {
dprintf("Error retrieving attrib name from path: %s\n", path);
sysfs_close_attribute(sysattr);
return NULL;
}
safestrcpy(sysattr->path, path);
if ((stat(sysattr->path, &fileinfo)) != 0) {
dprintf("Stat failed: No such attribute?\n");
sysattr->method = 0;
free(sysattr);
sysattr = NULL;
} else {
if (fileinfo.st_mode & S_IRUSR)
sysattr->method |= SYSFS_METHOD_SHOW;
if (fileinfo.st_mode & S_IWUSR)
sysattr->method |= SYSFS_METHOD_STORE;
}
return sysattr;
}
示例14: userinit
//PAGEBREAK: 32
// Set up first user process.
void userinit(void) {
struct proc *p;
extern char _binary_initcode_start[], _binary_initcode_size[];
p = allocproc();
initproc = p;
if ((p->pgdir = setupkvm()) == 0)
panic("userinit: out of memory?");
inituvm(p->pgdir, _binary_initcode_start, (int) _binary_initcode_size);
p->sz = PGSIZE;
memset(p->tf, 0, sizeof(*p->tf));
p->tf->cs = (SEG_UCODE << 3) | DPL_USER;
p->tf->ds = (SEG_UDATA << 3) | DPL_USER;
p->tf->es = p->tf->ds;
p->tf->ss = p->tf->ds;
p->tf->eflags = FL_IF;
p->tf->esp = PGSIZE;
p->tf->eip = 0; // beginning of initcode.S
safestrcpy(p->name, "initcode", sizeof(p->name));
p->cwd = namei("/");
p->parent=0;
setpriority(p,0);
SetProcessRunnable(p);
}
示例15: userinit
//PAGEBREAK: 32
// Set up first user process.
void
userinit(void)
{
struct proc *p;
extern char _binary_initcode_start[], _binary_initcode_size[];
p = allocproc();
initproc = p;
if((p->pgdir = setupkvm(kalloc)) == 0)
panic("userinit: out of memory?");
inituvm(p->pgdir, _binary_initcode_start, (int)_binary_initcode_size);
p->sz = PGSIZE;
memset(p->tf, 0, sizeof(*p->tf));
p->tf->cs = (SEG_UCODE << 3) | DPL_USER;
p->tf->ds = (SEG_UDATA << 3) | DPL_USER;
p->tf->es = p->tf->ds;
p->tf->ss = p->tf->ds;
p->tf->eflags = FL_IF;
p->tf->esp = PGSIZE;
p->tf->eip = 0; // beginning of initcode.S
safestrcpy(p->name, "initcode", sizeof(p->name));
p->cwd = namei("/");
p->state = RUNNABLE;
createInternalProcess("inSwapper",(void*)inSwapper);
}