{
if (pkt->maxlen < length) {
pkt->maxlen = length + 256;
- pkt->data = srealloc(pkt->data, pkt->maxlen);
+ pkt->data = sresize(pkt->data, pkt->maxlen, char);
}
}
static void sftp_pkt_adddata(struct sftp_packet *pkt, void *data, int len)
static struct sftp_packet *sftp_pkt_init(int pkt_type)
{
struct sftp_packet *pkt;
- pkt = smalloc(sizeof(struct sftp_packet));
+ pkt = snew(struct sftp_packet);
pkt->data = NULL;
pkt->savedpos = -1;
pkt->length = 0;
if (!sftp_recvdata(x, 4))
return NULL;
- pkt = smalloc(sizeof(struct sftp_packet));
+ pkt = snew(struct sftp_packet);
pkt->savedpos = 0;
pkt->length = pkt->maxlen = GET_32BIT(x);
- pkt->data = smalloc(pkt->length);
+ pkt->data = snewn(pkt->length, char);
if (!sftp_recvdata(pkt->data, pkt->length)) {
sftp_pkt_free(pkt);
static char *mkstr(char *s, int len)
{
- char *p = smalloc(len + 1);
+ char *p = snewn(len + 1, char);
memcpy(p, s, len);
p[len] = '\0';
return p;
sftp_pkt_free(pktin);
return NULL;
}
- handle = smalloc(sizeof(struct fxp_handle));
+ handle = snew(struct fxp_handle);
handle->hstring = mkstr(hstring, len);
handle->hlen = len;
sftp_pkt_free(pktin);
sftp_pkt_free(pktin);
return NULL;
}
- handle = smalloc(sizeof(struct fxp_handle));
+ handle = snew(struct fxp_handle);
handle->hstring = mkstr(hstring, len);
handle->hlen = len;
sftp_pkt_free(pktin);
if (pktin->type == SSH_FXP_NAME) {
struct fxp_names *ret;
int i;
- ret = smalloc(sizeof(struct fxp_names));
+ ret = snew(struct fxp_names);
ret->nnames = sftp_pkt_getuint32(pktin);
- ret->names = smalloc(ret->nnames * sizeof(struct fxp_name));
+ ret->names = snewn(ret->nnames, struct fxp_name);
for (i = 0; i < ret->nnames; i++) {
char *str;
int len;
sfree(names->names);
sfree(names);
}
+
+/*
+ * Duplicate an fxp_name structure.
+ */
+struct fxp_name *fxp_dup_name(struct fxp_name *name)
+{
+ struct fxp_name *ret;
+ ret = snew(struct fxp_name);
+ ret->filename = dupstr(name->filename);
+ ret->longname = dupstr(name->longname);
+ ret->attrs = name->attrs; /* structure copy */
+ return ret;
+}
+
+/*
+ * Free up an fxp_name structure.
+ */
+void fxp_free_name(struct fxp_name *name)
+{
+ sfree(name->filename);
+ sfree(name->longname);
+ sfree(name);
+}