Check if stdout is a terminal, if so, print a verbose message.
[tinc] / src / genauth.c
index 0d47d51..895ed7b 100644 (file)
@@ -60,7 +60,7 @@ int main(int argc, char **argv)
   p = xmalloc(bytes);
 
   setbuf(stdout, NULL);
-  for(i = 0; i < 128; i++)
+  for(i = 0; i < bytes; i++)
     {
       c = fgetc(fp);
       if(feof(fp))
@@ -70,23 +70,24 @@ int main(int argc, char **argv)
         }
       p[i] = c;
     }
+  fclose(fp);
 
-  for(i = 0; i < (bytes); i++)
+  if(isatty(1))
     {
-      c = fgetc(fp);
-      if(feof(fp))
-       {
-         puts("");
-         fprintf(stderr, "File was empty!\n");
-       }
-      p[i] = c;
+      fprintf(stderr, ": done.\nThe following line should be ENTIRELY copied into a passphrase file:\n");
+      printf("%d ", bits);
+      for(i = 0; i < bytes; i++)
+       printf("%02x", p[i]);
+      puts("");
+    }
+  else
+    {
+      printf("%d ", bits);
+      for(i = 0; i < bytes; i++)
+       printf("%02x", p[i]);
+      puts("");
+      fprintf(stderr, ": done.\n");
     }
-  fclose(fp);
-
-  printf("%d ", bits);
-  for(i = 0; i < bytes; i++)
-    printf("%02x", p[i]);
-  puts("");
 
   return 0;
 }