BOOTSTRAP (kutils) functions


LIBRARY ROUTINE

kstrdup - return a duplicate of the input string

LIBRARY CALL

char *kstrdup(
   const char *istr)

INPUT

OUTPUT

none

RETURN VALUE

A pointer to the duplicated string. This routine will return NULL on a memory allocation error, or if the input string is NULL.

DESCRIPTION

This function allocates memory and copies the input string into that space. This routine is similiar to the system routine strdup. It uses kdupalloc() to create a memory buffer large enough to hold the string passed into this routine and copyies the input string to the buffer. This buffer is then returned to the user.

ADDITIONAL INFORMATION

none

EXAMPLES

This example initialized the a pointer to be a memory buffer with a string in it. This buffer can then be modified by the rest of the routine. Since memory is allocated, a call to kfree_and_NULL() will free the buffer when the buffer is no longer needed.
char *str = kstrdup("this sentence needs a capital t at the start.");
if (str == NULL)
{
  kerror(NULL, NULL, "Cannot malloc space for the string");
  return;
}
str[0] = 'T';
kprintf("%s\n", str);
The resulting print will be 'This sentence needs a capital t at the start.'

SIDE EFFECTS

none

RESTRICTIONS

none

MODIFICATION

none

FILES

$BOOTSTRAP/objects/library/kutils/src/strings.c

SEE ALSO

kutils(3)

COPYRIGHT

Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.