2 * PuTTY miscellaneous Unix stuff
10 #include <sys/types.h>
15 long tickcount_offset
= 0;
17 unsigned long getticks(void)
20 gettimeofday(&tv
, NULL
);
22 * We want to use milliseconds rather than microseconds,
23 * because we need a decent number of them to fit into a 32-bit
24 * word so it can be used for keepalives.
26 return tv
.tv_sec
* 1000 + tv
.tv_usec
/ 1000 + tickcount_offset
;
29 Filename
filename_from_str(const char *str
)
32 strncpy(ret
.path
, str
, sizeof(ret
.path
));
33 ret
.path
[sizeof(ret
.path
)-1] = '\0';
37 const char *filename_to_str(const Filename
*fn
)
42 int filename_equal(Filename f1
, Filename f2
)
44 return !strcmp(f1
.path
, f2
.path
);
47 int filename_is_null(Filename fn
)
53 static FILE *debug_fp
= NULL
;
58 debug_fp
= fopen("debug.log", "w");
61 write(1, buf
, strlen(buf
));
68 char *get_username(void)
72 char *user
, *ret
= NULL
;
75 * First, find who we think we are using getlogin. If this
76 * agrees with our uid, we'll go along with it. This should
77 * allow sharing of uids between several login names whilst
78 * coping correctly with people who have su'ed.
86 if (p
&& p
->pw_uid
== uid
) {
88 * The result of getlogin() really does correspond to
94 * If that didn't work, for whatever reason, we'll do
95 * the simpler version: look up our uid in the password
96 * file and map it straight to a name.
109 * Display the fingerprints of the PGP Master Keys to the user.
110 * (This is here rather than in uxcons because it's appropriate even for
113 void pgp_fingerprints(void)
115 fputs("These are the fingerprints of the PuTTY PGP Master Keys. They can\n"
116 "be used to establish a trust path from this executable to another\n"
117 "one. See the manual for more information.\n"
118 "(Note: these fingerprints have nothing to do with SSH!)\n"
120 "PuTTY Master Key (RSA), 1024-bit:\n"
121 " " PGP_RSA_MASTER_KEY_FP
"\n"
122 "PuTTY Master Key (DSA), 1024-bit:\n"
123 " " PGP_DSA_MASTER_KEY_FP
"\n", stdout
);
127 * Set FD_CLOEXEC on a file descriptor
129 int cloexec(int fd
) {
132 fdflags
= fcntl(fd
, F_GETFD
);
133 if (fdflags
== -1) return -1;
134 return fcntl(fd
, F_SETFD
, fdflags
| FD_CLOEXEC
);