Back to index

lightning-sunbird  0.9+nobinonly
Functions
mdmac.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

PR_BEGIN_EXTERN_C void PStrFromCStr (const char *src, Str255 dst)
void CStrFromPStr (ConstStr255Param pString, char **cString)

Function Documentation

void CStrFromPStr ( ConstStr255Param  pString,
char **  cString 
)

Definition at line 452 of file mdmac.c.

{
       // Allocates a cString and copies a Pascal string into it.
       unsigned int  len;
       
       len = pString[0];
       *cString = malloc(len+1);
       
       if (*cString != NULL) {
              strncpy(*cString, (char *)&pString[1], len);
              (*cString)[len] = NULL;
       }
}

Here is the caller graph for this function:

PR_BEGIN_EXTERN_C void PStrFromCStr ( const char *  src,
Str255  dst 
)

Definition at line 407 of file mdmac.c.

{
       short  length  = 0;
       
       // handle case of overlapping strings
       if ( (void*)src == (void*)dst )
       {
              unsigned char*              curdst = &dst[1];
              unsigned char        thisChar;
                            
              thisChar = *(const unsigned char*)src++;
              while ( thisChar != '\0' ) 
              {
                     unsigned char nextChar;
                     
                     // use nextChar so we don't overwrite what we are about to read
                     nextChar = *(const unsigned char*)src++;
                     *curdst++ = thisChar;
                     thisChar = nextChar;
                     
                     if ( ++length >= 255 )
                            break;
              }
       }
       else if ( src != NULL )
       {
              unsigned char*              curdst = &dst[1];
              short                       overflow = 255;             // count down so test it loop is faster
              register char        temp;
       
              // Can't do the K&R C thing of "while (*s++ = *t++)" because it will copy trailing zero
              // which might overrun pascal buffer.  Instead we use a temp variable.
              while ( (temp = *src++) != 0 ) 
              {
                     *(char*)curdst++ = temp;
                            
                     if ( --overflow <= 0 )
                            break;
              }
              length = 255 - overflow;
       }
       dst[0] = length;
}

Here is the caller graph for this function: