*/
static int psftp_connect(char *userhost, char *user, int portnumber);
-static void do_sftp_init(void);
+static int do_sftp_init(void);
/* ----------------------------------------------------------------------
* sftp client state.
*/
static int sftp_ls_compare(const void *av, const void *bv)
{
- const struct fxp_name *a = (const struct fxp_name *) av;
- const struct fxp_name *b = (const struct fxp_name *) bv;
- return strcmp(a->filename, b->filename);
+ const struct fxp_name *const *a = (const struct fxp_name *const *) av;
+ const struct fxp_name *const *b = (const struct fxp_name *const *) bv;
+ return strcmp((*a)->filename, (*b)->filename);
}
int sftp_cmd_ls(struct sftp_command *cmd)
{
struct fxp_handle *dirh;
struct fxp_names *names;
- struct fxp_name *ournames;
+ struct fxp_name **ournames;
int nnames, namesize;
char *dir, *cdir;
int i;
}
for (i = 0; i < names->nnames; i++)
- ournames[nnames++] = names->names[i];
+ ournames[nnames++] = fxp_dup_name(&names->names[i]);
- names->nnames = 0; /* prevent free_names */
fxp_free_names(names);
}
fxp_close(dirh);
/*
* And print them.
*/
- 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);
}
sfree(cdir);
strcat(str, "\n");
fputs(str, stderr);
- exit(1);
+ cleanup_exit(1);
}
void connection_fatal(char *fmt, ...)
{
strcat(str, "\n");
fputs(str, stderr);
- exit(1);
+ cleanup_exit(1);
}
void ldisc_send(char *buf, int len, int interactive)
unsigned char *p = (unsigned char *) data;
unsigned len = (unsigned) datalen;
+ assert(len > 0);
+
/*
* stderr data is just spouted to local stderr and otherwise
* ignored.
winsock_ver = MAKEWORD(1, 1);
if (WSAStartup(winsock_ver, &wsadata)) {
fprintf(stderr, "Unable to initialise WinSock");
- exit(1);
+ cleanup_exit(1);
}
if (LOBYTE(wsadata.wVersion) != 1 || HIBYTE(wsadata.wVersion) != 1) {
fprintf(stderr, "WinSock version is incompatible with 1.1");
- exit(1);
+ cleanup_exit(1);
}
}
printf(" -v show verbose messages\n");
printf(" -P port connect to specified port\n");
printf(" -pw passw login with specified password\n");
- exit(1);
+ cleanup_exit(1);
}
/*
printf("login as: ");
if (!fgets(cfg.username, sizeof(cfg.username), stdin)) {
fprintf(stderr, "psftp: aborting\n");
- exit(1);
+ cleanup_exit(1);
} else {
int len = strlen(cfg.username);
if (cfg.username[len - 1] == '\n')