Strings

tableBASE does not use NULL-terminated strings for the different fields of type character [ ] (table names, passwords, etc.). If any of these strings are less than the maximum allowed size, they must be padded with spaces (the character 0x40 in EBCDIC).

An example of a routine to add this padding (as required) to a standard C NULL-terminated string is provided as part of the C examples in this manual. Its prototype is

fixStringLength( szInput, sOutput, int nMaximumLength );

Here is an example of a routine to add this padding (as required) to a standard C NULL-terminated string:

/*              
 * This function could be updated to return an error if the input 
 * string is longer than out_len+1, counting the '\0'. 
 */ 
int fixStringLength( char* input, char* output, size_t out_len ) 
{ 
  size_t len_2_copy = 0, i = 0; 
  const char *ptr; 
                                                                    
  /* 
   * memchr() is used to avoid buffer overflow as there is 
   * no strnlen() in z/OS. 
   */ 
  ptr = (const char *)memchr(input, '\0', out_len); 
  len_2_copy = ptr ? (size_t)(ptr - input) : out_len; 
  /* 
   * If the input length is less than out_len, we append the 
   * output string with spaces (faster than doing memset()). 
   */ 
  strncpy( output, input, len_2_copy ); 
  for ( i = len_2_copy; i < out_len; i++ ) 
      output[i] = ' '; 
                                                                    
  return 0; 
}