C++ (Cpp) strdup Examples

C++ (Cpp) strdup - 30 examples found. These are the top rated real world C++ (Cpp) examples of strdup extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
static char *
netsnmp_unix_fmtaddr(netsnmp_transport *t, void *data, int len)
{
    struct sockaddr_un *to = NULL;

    if (data != NULL) {
        to = (struct sockaddr_un *) data;
    } else if (t != NULL && t->data != NULL) {
        to = &(((sockaddr_un_pair *) t->data)->server);
        len = SUN_LEN(to);
    }
    if (to == NULL) {
        /*
         * "Local IPC" is the Posix.1g term for Unix domain protocols,
         * according to W. R. Stevens, ``Unix Network Programming Volume I
         * Second Edition'', p. 374.
         */
        return strdup("Local IPC: unknown");
    } else if (to->sun_path[0] == 0) {
        /*
         * This is an abstract name.  We could render it as hex or something
         * but let's not worry about that for now.
         */
        return strdup("Local IPC: abstract");
    } else {
        char           *tmp = (char *) malloc(16 + len);
        if (tmp != NULL) {
            sprintf(tmp, "Local IPC: %s", to->sun_path);
        }
        return tmp;
    }
}
Example #2
0
static wbcErr wbc_create_error_info(const struct winbindd_response *resp,
                                    struct wbcAuthErrorInfo **_e)
{
    wbcErr wbc_status = WBC_ERR_SUCCESS;
    struct wbcAuthErrorInfo *e;

    e = (struct wbcAuthErrorInfo *)wbcAllocateMemory(
            1, sizeof(struct wbcAuthErrorInfo),
            wbcAuthErrorInfoDestructor);
    BAIL_ON_PTR_ERROR(e, wbc_status);

    e->nt_status = resp->data.auth.nt_status;
    e->pam_error = resp->data.auth.pam_error;
    e->nt_string = strdup(resp->data.auth.nt_status_string);
    BAIL_ON_PTR_ERROR(e->nt_string, wbc_status);

    e->display_string = strdup(resp->data.auth.error_string);
    BAIL_ON_PTR_ERROR(e->display_string, wbc_status);

    *_e = e;
    e = NULL;

done:
    wbcFreeMemory(e);
    return wbc_status;
}
Example #3
0
void parse_variable(char *cfg_filename, char *line, char *space)
{
    char space2[BUFSIZE] = { 0 };
    char *value = NULL;
    char *key = NULL;
    tTokenizer t;

    /* Space2 = space + '.' */
    if (space != NULL)
        snprintf(space2, sizeof(space2), "%s.", space);

    if ((strncmp(line, space2, strlen(space2)) == 0) ||
            ((space == NULL) && (strstr(line, ".") != NULL))) {
        t = tokenize(line, "=");
        if (t.numTokens != 2) {
            DPRINTF("%s: Warning! There are %d tokens instead of 2. Ignoring line: '%s'\n",
                    __FUNCTION__, t.numTokens, line);
            return;
        }
        key   = strdup(trim(t.tokens[0]));
        value = strdup(trim(t.tokens[1]));
        free_tokens(t);

        if (space == NULL) {
            space = strdup(key);
            space[ strlen(space) - strlen(strchr(space, '.')) ] = 0;
            snprintf(space2, sizeof(space2), "%s.", space);
        }

        if (config_variable_add( cfg_filename, space, key + strlen(space2), value, key) != 0)
            fprintf(stderr, "Warning: Cannot add configuration variable '%s'\n", key);
    }
}
Example #4
0
/** Parses an entry of a user in the config
 * @param doc the xml document
 * @param cur the current xml node
 * @return 0 on success, -1 on failure
 */
int parseUser(xmlDoc *doc, xmlNode *cur)
{
    xmlChar *key;
    cur = cur->xmlChildrenNode;
    lp_user *user = g_new0(lp_user, 1);


    while (cur)
    {
        key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
        if ((!xmlStrcmp(cur->name, (const xmlChar *)"login")))
            user->login = strdup((char*)key);
        else if ((!xmlStrcmp(cur->name, (const xmlChar *)"pass")))
            user->pass = strdup((char*)key);
        else if ((!xmlStrcmp(cur->name, (const xmlChar *)"email")))
            user->email = strdup((char*)key);
        else if ((!xmlStrcmp(cur->name, (const xmlChar *)"right_db")))
        {
            if(atoi((char*)key))
                user->rights |= LP_RIGHT_DB;
        }
        else if ((!xmlStrcmp(cur->name, (const xmlChar *)"right_op")))
        {
            if(atoi((char*)key))
                user->rights |= LP_RIGHT_OP;
        }
        xmlFree(key);
        cur = cur->next;
    }
    config->users = g_list_append(config->users, user);
    return(0);
}
Example #5
0
static void
openFiles(struct CmdlineInfo const cmdline,
          unsigned int *     const fileCtP,
          struct pam **      const imgPamP,
          const char ***     const namesP) {

    unsigned int fileCt;
    struct pam * imgPam;
    const char ** names;

    fileCt = cmdline.nFiles > 0 ? cmdline.nFiles : 1;

    MALLOCARRAY(imgPam, fileCt);
    MALLOCARRAY(names, fileCt);

    if (!imgPam || !names)
        pm_error("out of memory");

    if (cmdline.nFiles > 0) {
        unsigned int i;

        for (i = 0; i < cmdline.nFiles; ++i) {
            imgPam[i].file = pm_openr(cmdline.inFileName[i]);
            names[i] = strdup(cmdline.inFileName[i]);
        }
    } else {
        imgPam[0].file = stdin;
        names[0] = strdup("stdin");
    }

    *fileCtP = fileCt;
    *imgPamP = imgPam;
    *namesP  = names;
}
Example #6
0
Preferences::Preferences(const char* name, const char* signature, bool doSave)
    : BMessage('Pref'), BLocker("Preferences", true),
      fSavePreferences(doSave)
{
    fNewPreferences = false;
    fSettingsFile = 0;
    BPath prefpath;
    fName = strdup(name);
    if (signature)
        fSignature = strdup(signature);
    else
        fSignature = NULL;

    if (find_directory(B_USER_SETTINGS_DIRECTORY, &prefpath) == B_OK) {
        BDirectory prefdir(prefpath.Path());
        BEntry entry;
        prefdir.FindEntry(fName, &entry);

        BFile file(&entry, B_READ_ONLY);
        if (file.InitCheck() == B_OK)
            Unflatten(&file);
        else
            fNewPreferences = true;
    }
}