for (i = 0; i < nnames; i++) printf("%s\n", ournames[i].longname);
for (i = 0; i < nnames; i++) { printf("%s\n", ournames[i]->longname); fxp_free_name(ournames[i]); } sfree(ournames);
int sftp_cmd_ls(struct sftp_command *cmd){    struct fxp_handle *dirh;    struct fxp_names *names;    struct fxp_name *ournames;    int nnames, namesize;    char *dir, *cdir;    int i;    if (back == NULL) {	printf("psftp: not connected to a host; use \"open host.name\"\n");	return 0;    }    if (cmd->nwords < 2)	dir = ".";    else	dir = cmd->words[1];    cdir = canonify(dir);    if (!cdir) {	printf("%s: %s\n", dir, fxp_error());	return 0;    }    printf("Listing directory %s\n", cdir);    dirh = fxp_opendir(cdir);    if (dirh == NULL) {	printf("Unable to open %s: %s\n", dir, fxp_error());    } else {	nnames = namesize = 0;	ournames = NULL;	while (1) {	    names = fxp_readdir(dirh);	    if (names == NULL) {		if (fxp_error_type() == SSH_FX_EOF)		    break;		printf("Reading directory %s: %s\n", dir, fxp_error());		break;	    }	    if (names->nnames == 0) {		fxp_free_names(names);		break;	    }	    if (nnames + names->nnames >= namesize) {		namesize += names->nnames + 128;		ournames =		    srealloc(ournames, namesize * sizeof(*ournames));	    }	    for (i = 0; i < names->nnames; i++)		ournames[nnames++] = names->names[i];	    names->nnames = 0;	       /* prevent free_names */	    fxp_free_names(names);	}	fxp_close(dirh);	/*	 * Now we have our filenames. Sort them by actual file	 * name, and then output the longname parts.	 */	qsort(ournames, nnames, sizeof(*ournames), sftp_ls_compare);	/*	 * And print them.	 */	for (i = 0; i < nnames; i++)	    printf("%s\n", ournames[i].longname);    }    sfree(cdir);    return 1;}