Use the same tmp dir pattern as in opkg_update_cmd().
[oweals/opkg-lede.git] / libopkg / user.c
index 98ab7b903543982aaef9c52e4a5e9ef06a451fb0..26f6f0eaaf1a07080c1622ccdda73c0ca5915312 100644 (file)
@@ -1,4 +1,4 @@
-/* user.c - the itsy package management system
+/* user.c - the opkg package management system
 
    Jamey Hicks
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.
 */
-
 #include <stdio.h>
 #include <stdarg.h>
+#include <unistd.h>
 #include "file_util.h"
 #include "str_util.h"
-#ifdef OPKG_LIB        
-#include "libopkg.h"
-#endif 
-
 
-#ifdef OPKG_LIB
-static char *question = NULL;
-static int question_len = 255;
-#endif 
 char *get_user_response(const char *format, ...)
 {
-     int len = question_len;
-     va_list ap;
-     char *response;
-     va_start(ap, format);
-
-#ifndef OPKG_LIB
-     vprintf(format, ap);
-     do {
-         response = file_read_line_alloc(stdin);
-     } while (response == NULL);
-#else
-     do {
-         if (question == NULL || len > question_len) {
-              question = realloc(question, len + 1);
-              question_len = len;
-         }
-         len = vsnprintf(question,question_len,format,ap);
-     } while (len > question_len);
-     response = strdup(opkg_cb_response(question));
-#endif
-     str_chomp(response);
-     str_tolower(response);
-
-     return response;
+       va_list ap;
+       char *response;
+
+       va_start(ap, format);
+       vprintf(format, ap);
+       va_end(ap);
+
+       if (!isatty(fileno(stdin)))
+               return NULL;
+
+       response = (char *)file_read_line_alloc(stdin);
+       if (response == NULL)
+               return NULL;
+
+       str_chomp(response);
+       str_tolower(response);
+
+       return response;
 }