Example: strdup

In this example, the group name of a Vuser is converted to lower case. However, lr_whoami returns the group name as a static buffer and such buffers cannot be manipulated with. If manipulation is required, a copy of the static buffer must be created.

strdup creates a copy of the static buffer, groupname_static. The characters in the new buffer, groupname, arethen converted to lower case.

    #include <string.h>
    int id;
    char * groupname_static, * groupname;
    // Get the group name from VuGen 
    lr_whoami (&id, &groupname_static, NULL);
    lr_output_message ("groupname=%s", groupname_static);
    // Make a copy of groupname_static so we can change it
    groupname = (char *)strdup(groupname_static);
    groupname = (char *)strlwr(groupname);
    lr_output_message ("lower case groupname=%s", groupname);
    free(groupname);
Output:
Action.c(8): groupname=None
Action.c(14): lower case groupname=none