Implement "putty -cleanup"
[sgt/putty] / noise.c
diff --git a/noise.c b/noise.c
index cf9bba5..383e6c3 100644 (file)
--- a/noise.c
+++ b/noise.c
@@ -73,7 +73,7 @@ void noise_get_heavy(void (*func) (void *, int)) {
                       FILE_SHARE_READ | FILE_SHARE_WRITE,
                       NULL, OPEN_EXISTING, 0, NULL);
 
-    if (seedf) {
+    if (seedf != INVALID_HANDLE_VALUE) {
        while (1) {
            char buf[1024];
            DWORD len;
@@ -96,7 +96,7 @@ void random_save_seed(void) {
     seedf = CreateFile(seedpath, GENERIC_WRITE, 0,
                       NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
 
-    if (seedf) {
+    if (seedf != INVALID_HANDLE_VALUE) {
        int len;
        DWORD lenwritten;
        void *data;
@@ -108,6 +108,16 @@ void random_save_seed(void) {
 }
 
 /*
+ * This function is called from `putty -cleanup'. It removes the
+ * random seed file.
+ */
+void random_destroy_seed(void) {
+    if (!seedpath[0])
+       get_seedpath();
+    remove(seedpath);
+}
+
+/*
  * This function is called every time the random pool needs
  * stirring, and will acquire the system time in all available
  * forms and the battery status.
@@ -124,8 +134,10 @@ void noise_get_light(void (*func) (void *, int)) {
     GetSystemTimeAdjustment(&adjust[0], &adjust[1], &rubbish);
     func(&adjust, sizeof(adjust));
 
+#ifndef WIN32S_COMPAT
     if (GetSystemPowerStatus(&pwrstat))
        func(&pwrstat, sizeof(pwrstat));
+#endif
 }
 
 /*