aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c19
-rw-r--r--lib/portability.h21
2 files changed, 26 insertions, 14 deletions
diff --git a/lib/lib.c b/lib/lib.c
index a1f4a528..6a2e7d98 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -794,18 +794,21 @@ void terminal_size(unsigned *x, unsigned *y)
// This should use a raw tty, fixit later.
int yesno(char *prompt, int def)
{
+ FILE *fp = fopen("/dev/tty", "rw");
char buf;
- int i;
- for (i=0; i<3 && !isatty(i); i++);
- if (i == 3) return 1;
+ if (!fp) return 1;
+
+ fprintf(fp, "%s (%c/%c):", prompt, def ? 'Y' : 'y', def ? 'n' : 'N');
+ while (fread(&buf, 1, 1, fp)) {
+ if (tolower(buf) == 'y') def = 1;
+ if (tolower(buf) == 'n') def = 0;
+ else if (!isspace(buf)) continue;
- fdprintf(i, "%s (%c/%c):", prompt, def ? 'Y' : 'y', def ? 'n' : 'N');
- while (read(i, &buf, 1)) {
- if (isspace(buf)) break;
- if (tolower(buf) == 'y') return 1;
- if (tolower(buf) == 'n') return 0;
+ break;
}
+ fclose(fp);
+
return def;
}
diff --git a/lib/portability.h b/lib/portability.h
index 832dd123..9b8d294f 100644
--- a/lib/portability.h
+++ b/lib/portability.h
@@ -9,13 +9,22 @@
#define _FILE_OFFSET_BITS 64
-#define _POSIX_C_SOURCE 200809L
-#define _XOPEN_SOURCE 600
-#define _BSD_SOURCE
-#define _SVID_SOURCE
+#include <features.h>
-#include <stdio.h>
-#define fdprintf(...) dprintf(__VA_ARGS__)
+//#define _POSIX_C_SOURCE 200809L
+//#define _XOPEN_SOURCE 600
+//#define _BSD_SOURCE
+//#define _SVID_SOURCE
+
+//#include <stdio.h>
+//#define fdprintf(...) dprintf(__VA_ARGS__)
+
+#ifdef __GLIBC__
+// An SUSv4 function that glibc refuses to #define without crazy #defines,
+// see http://pubs.opengroup.org/onlinepubs/9699919799/functions/strptime.html
+#include <time.h>
+char *strptime(const char *buf, const char *format, struct tm *tm);
+#endif
#ifdef __GNUC__
#define noreturn __attribute__((noreturn))