fstring distinguished type

John Malmberg wb8tyw at qsl.net
Tue Jan 15 18:15:18 GMT 2002

How about passing arrays by a descriptor?

typedef struct {
     int tag;              /* Code to type of data. helps debug */
     int class;            /* Memory allocation */
     size_t allocation;    /* Maximum size of string */
     size_t currentsize;   /* Current used allocation */
     char * pointer;       /* Pointer to string data */
} string_dsc;

It adds a level of indirection, but has a lot of bennefits.

The tag can be used to indicate what the data is used for.
It is a magic number that is can be used by routines, but can also be 
very useful for debuging and sanity checks.

The class is used to determine how the data was allocated.  So that the 
routine knows if the string is dynamically allocated or static.  It can 
also indicate what pool the allication came from, and if it is permitted 
to reallocate the string to fit.

The allocation gives the bound.

The pointer in this case is the payload for the structure, the above can 
be used as a standard header for all structures that are passed between 
routines for better safety.

wb8tyw at qsl.network.
Personal Opinion Only

More information about the samba-technical mailing list