/trunk/kernel/generic/include/string.h |
---|
43,6 → 43,9 |
extern void strncpy(char *dest, const char *src, size_t len); |
extern char *strcpy(char *dest, const char *src); |
extern char *strchr(const char *s, int i); |
extern char *strrchr(const char *s, int i); |
#endif |
/** @} |
/trunk/kernel/generic/src/main/kinit.c |
---|
64,6 → 64,8 |
#include <security/cap.h> |
#include <lib/rd.h> |
#include <ipc/ipc.h> |
#include <debug.h> |
#include <string.h> |
#ifdef CONFIG_SMP |
#include <smp/smp.h> |
78,6 → 80,9 |
static char alive[ALIVE_CHARS] = "-\\|/"; |
#endif |
#define BOOT_PREFIX "boot:" |
#define BOOT_PREFIX_LEN 5 |
/** Kernel initialization thread. |
* |
* kinit takes care of higher level kernel |
175,11 → 180,23 |
continue; |
} |
char *name = init.tasks[i].name; |
if (name[0] == '\0') name = "init-bin"; |
/* |
* Construct task name from the 'boot:' prefix and the |
* name stored in the init structure (if any). |
*/ |
char namebuf[TASK_NAME_BUFLEN], *name; |
name = init.tasks[i].name; |
if (name[0] == '\0') name = "<unknown>"; |
ASSERT(TASK_NAME_BUFLEN >= BOOT_PREFIX_LEN); |
strncpy(namebuf, BOOT_PREFIX, TASK_NAME_BUFLEN); |
strncpy(namebuf + BOOT_PREFIX_LEN, name, |
TASK_NAME_BUFLEN - BOOT_PREFIX_LEN); |
int rc = program_create_from_image((void *) init.tasks[i].addr, |
name, &programs[i]); |
namebuf, &programs[i]); |
if ((rc == 0) && (programs[i].task != NULL)) { |
/* |
/trunk/kernel/generic/src/lib/string.c |
---|
161,5 → 161,46 |
return orig; |
} |
/** Find first occurence of character in string. |
* |
* @param s String to search. |
* @param i Character to look for. |
* |
* @return Pointer to character in @a s or NULL if not found. |
*/ |
extern char *strchr(const char *s, int i) |
{ |
while (*s != '\0') { |
if (*s == i) return (char *) s; |
++s; |
} |
return NULL; |
} |
/** Find last occurence of character in string. |
* |
* @param s String to search. |
* @param i Character to look for. |
* |
* @return Pointer to character in @a s or NULL if not found. |
*/ |
extern char *strrchr(const char *s, int i) |
{ |
const char *start; |
start = s; |
if (*s == '\0') return NULL; |
while (*s != '\0') ++s; |
while (s != start) { |
--s; |
if (*s == i) return (char *) s; |
} |
return NULL; |
} |
/** @} |
*/ |
/trunk/kernel/arch/ia32/src/boot/cboot.c |
---|
39,10 → 39,46 |
#include <config.h> |
#include <memstr.h> |
#include <string.h> |
#include <macros.h> |
/* This is a symbol so the type is only dummy. Obtain the value using &. */ |
extern int _hardcoded_unmapped_size; |
/** Extract command name from the multiboot module command line. |
* |
* @param buf Destination buffer (will always null-terminate). |
* @param n Size of destination buffer. |
* @param cmd_line Input string (the command line). |
*/ |
static void extract_command(char *buf, size_t n, const char *cmd_line) |
{ |
const char *start, *end, *cp; |
size_t max_len; |
/* Find the first space. */ |
end = strchr(cmd_line, ' '); |
if (end == NULL) end = cmd_line + strlen(cmd_line); |
/* |
* Find last occurence of '/' before 'end'. If found, place start at |
* next character. Otherwise, place start at beginning of buffer. |
*/ |
cp = end; |
start = buf; |
while (cp != start) { |
if (*cp == '/') { |
start = cp + 1; |
break; |
} |
--cp; |
} |
/* Copy the command and null-terminate the string. */ |
max_len = min(n - 1, (size_t) (end - start)); |
strncpy(buf, start, max_len + 1); |
buf[max_len] = '\0'; |
} |
/** C part of ia32 boot sequence. |
* @param signature Should contain the multiboot signature. |
* @param mi Pointer to the multiboot information structure. |
72,10 → 108,9 |
/* Copy command line, if available. */ |
if (mods[i].string) { |
strncpy(init.tasks[i].name, mods[i].string, |
CONFIG_TASK_NAME_BUFLEN - 1); |
init.tasks[i].name[CONFIG_TASK_NAME_BUFLEN - 1] |
= '\0'; |
extract_command(init.tasks[i].name, |
CONFIG_TASK_NAME_BUFLEN, |
mods[i].string); |
} else { |
init.tasks[i].name[0] = '\0'; |
} |