FreeBASIC  0.91.0
str_tempdescf.c
Go to the documentation of this file.
1 /* temp string descriptor allocation for fixed-len strings */
2 
3 #include "fb.h"
4 
5 FBCALL FBSTRING *fb_StrAllocTempDescF( char *str, ssize_t str_size )
6 {
7  FBSTRING *dsc;
8 
9  FB_STRLOCK();
10 
11  /* alloc a temporary descriptor */
12  dsc = fb_hStrAllocTmpDesc( );
13 
14  FB_STRUNLOCK();
15 
16  if( dsc == NULL )
17  return &__fb_ctx.null_desc;
18 
19  dsc->data = str;
20 
21  /* can't use strlen() if the size is known */
22  if( str_size != 0 )
23  dsc->len = str_size - 1; /* less the null-term */
24  else
25  {
26  if( str != NULL )
27  dsc->len = strlen( str );
28  else
29  dsc->len = 0;
30  }
31 
32  dsc->size = dsc->len;
33 
34  return dsc;
35 }