This is miscutil.c in view mode; [Download] [Up]
#include "miscutil.h"
#include "math.h"
/* given a pointer to a string, strdup wil allocate memory and
check to see if there was memory to perform malloc. if so, it then
copies the string into freshly allocated memory and returns a pointer
to the copy of the string. (defined in Van Wyk, but not in the Andrew
C libraries.
*/
extern malloc();
char *strdup(const char *string)
{
char *temp;
if (!(temp = (char *) malloc( (unsigned) strlen(string)+1))) {
return NULL;
}
(void) strcpy(temp, string);
return(temp);
}
char *strcatdup(const char *string1, const char *string2)
{
char *temp;
if (!(temp = (char *) malloc((strlen(string1)+strlen(string2)+1)
* sizeof(char))))
return NULL;
(void) strcpy(temp, string1);
strcat(temp, string2);
return(temp);
}
unsigned char floattobyte(float f)
{
return (unsigned char) rint(255.0*f);
}
float bytetofloat(unsigned char c)
{
return (float) c/255.0;
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.