ASCIIZToMaxLenStr

Converts an ASCIIZ (NULL-terminated) string to a length-preceded string that is not longer than the specified maximum length

Local Servers:blocking
Remote Servers:N/A
Classification:3.12, 3.2, 4.x, 5.x, 6.x
Service:String Conversion

Syntax

  #include <nwstring.h>  
   
  int ASCIIZToMaxLenStr  (  
     char   *lenString,   
     char   *ASCIIZstring,   
     int     maximumLength);
  

Parameters

lenString
(OUT) Points to the destination (length-preceded) string.
ASCIIZstring
(IN) Points to the source string in ASCIIZ format.
maximumLength
(IN) Specifies the maximum number of characters to place in the new string.

Return Values

The following table lists return values and descriptions.

Value

Name

Description

–1

EFAILURE

The ASCIIZ string was longer than the mamimumLength.

0

ESUCCES

 

Remarks

A length-preceded string has the length of the string in the first byte, followed by the characters in the string; it cannot exceed 255 characters. If the ASCIIZstring string is longer that 255 characters, this function returns EFAILURE, and lenString contains maximumLength characters. The remaining characters of the ASCIIZstring are not copied to lenString.

Since length-preceded strings only have one byte to store the size of the string, the maximum size of the string is 255. Passing a maximum size larger than 255 produces unpredictable results.

Example

  #include <nwstring.h>  
  #include <errno.h> 
    
  main()  
  {  
     char srcString[256];  
     char destString[256];  
     int ccode;  
     int maxSize;  
     strcpy(srcString,"This is the message");  
     maxSize = 100;  
     ccode = ASCIIZToMaxLenStr(destString, srcString, maxSize);  
     if(ccode == ESUCCESS)  
        printf("The string fits.\n");  
     else  
        printf("The string was too long to fit in the allotted
                space.\n");  
  }