mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-10 09:58:01 +00:00
1547c9c1ec
Up until now, it's been a variadic _function_, whose argument list consists of 'const char *' ASCIZ strings to concatenate, terminated by one containing a null pointer. Now, that function is dupcat_fn(), and it's wrapped by a C99 variadic _macro_ called dupcat(), which automatically suffixes the null-pointer terminating argument. This has three benefits. Firstly, it's just less effort at every call site. Secondly, it protects against the risk of accidentally leaving off the NULL, causing arbitrary words of stack memory to be dereferenced as char pointers. And thirdly, it protects against the more subtle risk of writing a bare 'NULL' as the terminating argument, instead of casting it explicitly to a pointer. That last one is necessary because C permits the macro NULL to expand to an integer constant such as 0, so NULL by itself may not have pointer type, and worse, it may not be marshalled in a variadic argument list in the same way as a pointer. (For example, on a 64-bit machine it might only occupy 32 bits. And yet, on another 64-bit platform, it might work just fine, so that you don't notice the mistake!) I was inspired to do this by happening to notice one of those bare NULL terminators, and thinking I'd better check if there were any more. Turned out there were quite a few. Now there are none.
94 lines
2.1 KiB
C
94 lines
2.1 KiB
C
/*
|
|
* Unix PuTTY main program.
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <ctype.h>
|
|
#include <stdlib.h>
|
|
#include <assert.h>
|
|
#include <unistd.h>
|
|
#include <gtk/gtk.h>
|
|
#include <gdk/gdk.h>
|
|
|
|
#define MAY_REFER_TO_GTK_IN_HEADERS
|
|
|
|
#include "putty.h"
|
|
#include "storage.h"
|
|
|
|
#include "gtkcompat.h"
|
|
|
|
/*
|
|
* Stubs to avoid uxpty.c needing to be linked in.
|
|
*/
|
|
const bool use_pty_argv = false;
|
|
char **pty_argv; /* never used */
|
|
char *pty_osx_envrestore_prefix;
|
|
|
|
/*
|
|
* Clean up and exit.
|
|
*/
|
|
void cleanup_exit(int code)
|
|
{
|
|
/*
|
|
* Clean up.
|
|
*/
|
|
sk_cleanup();
|
|
random_save_seed();
|
|
exit(code);
|
|
}
|
|
|
|
const struct BackendVtable *select_backend(Conf *conf)
|
|
{
|
|
const struct BackendVtable *vt =
|
|
backend_vt_from_proto(conf_get_int(conf, CONF_protocol));
|
|
assert(vt != NULL);
|
|
return vt;
|
|
}
|
|
|
|
void initial_config_box(Conf *conf, post_dialog_fn_t after, void *afterctx)
|
|
{
|
|
char *title = dupcat(appname, " Configuration");
|
|
create_config_box(title, conf, false, 0, after, afterctx);
|
|
sfree(title);
|
|
}
|
|
|
|
const bool use_event_log = true, new_session = true, saved_sessions = true;
|
|
const bool dup_check_launchable = true;
|
|
|
|
char *make_default_wintitle(char *hostname)
|
|
{
|
|
return dupcat(hostname, " - ", appname);
|
|
}
|
|
|
|
/*
|
|
* X11-forwarding-related things suitable for Gtk app.
|
|
*/
|
|
|
|
char *platform_get_x_display(void) {
|
|
const char *display;
|
|
/* Try to take account of --display and what have you. */
|
|
if (!(display = gdk_get_display()))
|
|
/* fall back to traditional method */
|
|
display = getenv("DISPLAY");
|
|
return dupstr(display);
|
|
}
|
|
|
|
const bool share_can_be_downstream = true;
|
|
const bool share_can_be_upstream = true;
|
|
|
|
void setup(bool single)
|
|
{
|
|
sk_init();
|
|
flags = FLAG_VERBOSE | FLAG_INTERACTIVE;
|
|
cmdline_tooltype |= TOOLTYPE_HOST_ARG | TOOLTYPE_PORT_ARG;
|
|
default_protocol = be_default_protocol;
|
|
/* Find the appropriate default port. */
|
|
{
|
|
const struct BackendVtable *vt =
|
|
backend_vt_from_proto(default_protocol);
|
|
default_port = 0; /* illegal */
|
|
if (vt)
|
|
default_port = vt->default_port;
|
|
}
|
|
}
|