sprintf(writemod, "wb");
sprintf(writemod, "w");
void logfopen(void *handle){    struct LogContext *ctx = (struct LogContext *)handle;    char buf[256];    time_t t;    struct tm tm;    char writemod[4];    /* Prevent repeat calls */    if (ctx->lgfp)	return;    if (!cfg.logtype)	return;    sprintf(writemod, "wb");	       /* default to rewrite */    time(&t);    tm = *localtime(&t);    /* substitute special codes in file name */    xlatlognam(ctx->currlogfilename, cfg.logfilename,cfg.host, &tm);    ctx->lgfp = fopen(ctx->currlogfilename, "r");  /* file already present? */    if (ctx->lgfp) {	int i;	fclose(ctx->lgfp);	i = askappend(ctx->frontend, ctx->currlogfilename);	if (i == 1)	    writemod[0] = 'a';	       /* set append mode */	else if (i == 0) {	       /* cancelled */	    ctx->lgfp = NULL;	    cfg.logtype = 0;	       /* disable logging */	    return;	}    }    ctx->lgfp = fopen(ctx->currlogfilename, writemod);    if (ctx->lgfp) {			       /* enter into event log */	/* --- write header line into log file */	fputs("=~=~=~=~=~=~=~=~=~=~=~= PuTTY log ", ctx->lgfp);	strftime(buf, 24, "%Y.%m.%d %H:%M:%S", &tm);	fputs(buf, ctx->lgfp);	fputs(" =~=~=~=~=~=~=~=~=~=~=~=\r\n", ctx->lgfp);	sprintf(buf, "%s session log (%s mode) to file: ",		(writemod[0] == 'a') ? "Appending" : "Writing new",		(cfg.logtype == LGTYP_ASCII ? "ASCII" :		 cfg.logtype == LGTYP_DEBUG ? "raw" :		 cfg.logtype == LGTYP_PACKETS ? "SSH packets" : "<ukwn>"));	/* Make sure we do not exceed the output buffer size */	strncat(buf, ctx->currlogfilename, 128);	buf[strlen(buf)] = '\0';	logevent(ctx->frontend, buf);    }}