1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-24 16:52:24 +00:00

Oops, Ben is quite right about the rather appalling design of

filename_from_str. Here's a better fix, with some const
repercussions too.

[originally from svn r2768]
This commit is contained in:
Simon Tatham 2003-02-01 17:24:27 +00:00
parent 947b70006e
commit bd16b29a7a
12 changed files with 30 additions and 29 deletions

View File

@ -66,7 +66,7 @@ int import_encrypted(const Filename *filename, int type, char **comment)
{
if (type == SSH_KEYTYPE_OPENSSH) {
/* OpenSSH doesn't do key comments */
*comment = dupstr(filename_to_str(*filename));
*comment = dupstr(filename_to_str(filename));
return openssh_encrypted(filename);
}
if (type == SSH_KEYTYPE_SSHCOM) {

View File

@ -146,7 +146,7 @@ void logfopen(void *handle)
ctx->cfg.logtype == LGTYP_DEBUG ? "raw" :
ctx->cfg.logtype == LGTYP_PACKETS ? "SSH packets" : "<ukwn>"));
/* Make sure we do not exceed the output buffer size */
strncat(buf, filename_to_str(ctx->currlogfilename), 128);
strncat(buf, filename_to_str(&ctx->currlogfilename), 128);
buf[strlen(buf)] = '\0';
logevent(ctx->frontend, buf);
}
@ -210,10 +210,11 @@ static void xlatlognam(Filename *dest, Filename src,
int size;
char buffer[FILENAME_MAX];
int len = sizeof(buffer)-1;
char *d, *s;
char *d;
const char *s;
d = buffer;
s = filename_to_str(src);
s = filename_to_str(&src);
while (*s) {
/* Let (bufp, len) be the string to append. */
@ -257,5 +258,5 @@ static void xlatlognam(Filename *dest, Filename src,
}
*d = '\0';
*dest = filename_from_str(s);
*dest = filename_from_str(d);
}

View File

@ -1,4 +1,4 @@
/* $Id: mac.c,v 1.39 2003/02/01 15:44:08 ben Exp $ */
/* $Id: mac.c,v 1.40 2003/02/01 17:24:26 simon Exp $ */
/*
* Copyright (c) 1999 Ben Harris
* All rights reserved.
@ -801,7 +801,7 @@ void platform_get_x11_auth(char *display, int *proto,
/* SGT: I have no idea whether Mac X servers need anything here. */
}
Filename filename_from_str(char *str)
Filename filename_from_str(const char *str)
{
Filename ret;
strncpy(ret.path, str, sizeof(ret.path));
@ -809,11 +809,9 @@ Filename filename_from_str(char *str)
return ret;
}
char *filename_to_str(Filename fn)
const char *filename_to_str(const Filename *fn)
{
/* FIXME: Memory leak! */
return dupstr(fn.path);
return fn->path;
}
int filename_equal(Filename f1, Filename f2)

View File

@ -166,7 +166,8 @@ void try_output(int is_stderr)
}
}
int from_backend(void *frontend_handle, int is_stderr, char *data, int len)
int from_backend(void *frontend_handle, int is_stderr,
const char *data, int len)
{
int osize, esize;

View File

@ -1528,7 +1528,7 @@ static unsigned char *outptr; /* where to put the data */
static unsigned outlen; /* how much data required */
static unsigned char *pending = NULL; /* any spare data */
static unsigned pendlen = 0, pendsize = 0; /* length and phys. size of buffer */
int from_backend(void *frontend, int is_stderr, char *data, int datalen)
int from_backend(void *frontend, int is_stderr, const char *data, int datalen)
{
unsigned char *p = (unsigned char *) data;
unsigned len = (unsigned) datalen;

View File

@ -597,7 +597,7 @@ int term_ldisc(Terminal *, int option);
void term_copyall(Terminal *);
void term_reconfig(Terminal *, Config *);
void term_seen_key_event(Terminal *);
int from_backend(void *, int is_stderr, char *data, int len);
int from_backend(void *, int is_stderr, const char *data, int len);
void term_provide_resize_fn(Terminal *term,
void (*resize_fn)(void *, int, int),
void *resize_ctx);
@ -790,8 +790,8 @@ extern const char *const x11_authnames[]; /* declared in x11fwd.c */
/*
* Miscellaneous exports from the platform-specific code.
*/
Filename filename_from_str(char *string);
char *filename_to_str(Filename fn);
Filename filename_from_str(const char *string);
const char *filename_to_str(const Filename *fn);
int filename_equal(Filename f1, Filename f2);
int filename_is_null(Filename fn);

2
scp.c
View File

@ -317,7 +317,7 @@ static unsigned char *outptr; /* where to put the data */
static unsigned outlen; /* how much data required */
static unsigned char *pending = NULL; /* any spare data */
static unsigned pendlen = 0, pendsize = 0; /* length and phys. size of buffer */
int from_backend(void *frontend, int is_stderr, char *data, int datalen)
int from_backend(void *frontend, int is_stderr, const char *data, int datalen)
{
unsigned char *p = (unsigned char *) data;
unsigned len = (unsigned) datalen;

8
ssh.c
View File

@ -734,7 +734,7 @@ static int alloc_channel_id(Ssh ssh)
return low + 1 + CHANNEL_NUMBER_OFFSET;
}
static void c_write(Ssh ssh, char *buf, int len)
static void c_write(Ssh ssh, const char *buf, int len)
{
if ((flags & FLAG_STDERR)) {
int i;
@ -746,7 +746,7 @@ static void c_write(Ssh ssh, char *buf, int len)
from_backend(ssh->frontend, 1, buf, len);
}
static void c_write_untrusted(Ssh ssh, char *buf, int len)
static void c_write_untrusted(Ssh ssh, const char *buf, int len)
{
int i;
for (i = 0; i < len; i++) {
@ -757,7 +757,7 @@ static void c_write_untrusted(Ssh ssh, char *buf, int len)
}
}
static void c_write_str(Ssh ssh, char *buf)
static void c_write_str(Ssh ssh, const char *buf)
{
c_write(ssh, buf, strlen(buf));
}
@ -2721,7 +2721,7 @@ static int do_ssh1_login(Ssh ssh, unsigned char *in, int inlen, int ispkt)
int ret = loadrsakey(&ssh->cfg.keyfile, &s->key, s->password);
if (ret == 0) {
c_write_str(ssh, "Couldn't load private key from ");
c_write_str(ssh, filename_to_str(ssh->cfg.keyfile));
c_write_str(ssh, filename_to_str(&ssh->cfg.keyfile));
c_write_str(ssh, ".\r\n");
continue; /* go and try password */
}

View File

@ -4602,7 +4602,7 @@ int term_ldisc(Terminal *term, int option)
/*
* from_backend(), to get data from the backend for the terminal.
*/
int from_backend(void *vterm, int is_stderr, char *data, int len)
int from_backend(void *vterm, int is_stderr, const char *data, int len)
{
Terminal *term = (Terminal *)vterm;

View File

@ -18,7 +18,7 @@ unsigned long getticks(void)
return tv.tv_sec * 1000000 + tv.tv_usec;
}
Filename filename_from_str(char *str)
Filename filename_from_str(const char *str)
{
Filename ret;
strncpy(ret.path, str, sizeof(ret.path));
@ -26,9 +26,9 @@ Filename filename_from_str(char *str)
return ret;
}
char *filename_to_str(Filename fn)
const char *filename_to_str(const Filename *fn)
{
return fn.path;
return fn->path;
}
int filename_equal(Filename f1, Filename f2)

View File

@ -208,7 +208,8 @@ void try_output(int is_stderr)
}
}
int from_backend(void *frontend_handle, int is_stderr, char *data, int len)
int from_backend(void *frontend_handle, int is_stderr,
const char *data, int len)
{
int osize, esize;

View File

@ -13,7 +13,7 @@ void platform_get_x11_auth(char *display, int *proto,
/* We don't support this at all under Windows. */
}
Filename filename_from_str(char *str)
Filename filename_from_str(const char *str)
{
Filename ret;
strncpy(ret.path, str, sizeof(ret.path));
@ -21,9 +21,9 @@ Filename filename_from_str(char *str)
return ret;
}
char *filename_to_str(Filename fn)
const char *filename_to_str(const Filename *fn)
{
return fn.path;
return fn->path;
}
int filename_equal(Filename f1, Filename f2)