Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2013-02-02 19:58:50 +1000
committerAllan McRae <allan@archlinux.org>2013-02-07 10:48:11 +1000
commit7956441350f0de11394de9afdcf95a54d608bc47 (patch)
tree7e98b8f814aeadfc2b59b7ec675f1d8d32458892
parent5c5cdb0eb964e1806c868e4deb84afa04c13bb75 (diff)
Better error message with "-" is specified without stdin
Signed-off-by: Allan McRae <allan@archlinux.org>
-rw-r--r--src/pacman/pacman.c95
1 files changed, 51 insertions, 44 deletions
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index dad12c5c..088511bd 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -809,54 +809,61 @@ int main(int argc, char *argv[])
}
/* we support reading targets from stdin if a cmdline parameter is '-' */
- if(!isatty(fileno(stdin)) && alpm_list_find_str(pm_targets, "-")) {
- size_t current_size = PATH_MAX;
- char *vdata, *line = malloc(current_size);
-
- /* remove the '-' from the list */
- pm_targets = alpm_list_remove_str(pm_targets, "-", &vdata);
- free(vdata);
-
- i = 0;
- while((line[i] = (char)fgetc(stdin)) != EOF) {
- if(isspace((unsigned char)line[i])) {
- /* avoid adding zero length arg when multiple spaces separate args */
- if(i > 0) {
- line[i] = '\0';
- pm_targets = alpm_list_add(pm_targets, strdup(line));
- i = 0;
- }
- } else {
- i++;
- /* we may be at the end of our allocated buffer now */
- if(i >= current_size) {
- char *new = realloc(line, current_size * 2);
- if(new) {
- line = new;
- current_size *= 2;
- } else {
- free(line);
- line = NULL;
- break;
+ if(alpm_list_find_str(pm_targets, "-")) {
+ if(!isatty(fileno(stdin))) {
+ size_t current_size = PATH_MAX;
+ char *vdata, *line = malloc(current_size);
+
+ /* remove the '-' from the list */
+ pm_targets = alpm_list_remove_str(pm_targets, "-", &vdata);
+ free(vdata);
+
+ i = 0;
+ while((line[i] = (char)fgetc(stdin)) != EOF) {
+ if(isspace((unsigned char)line[i])) {
+ /* avoid adding zero length arg when multiple spaces separate args */
+ if(i > 0) {
+ line[i] = '\0';
+ pm_targets = alpm_list_add(pm_targets, strdup(line));
+ i = 0;
+ }
+ } else {
+ i++;
+ /* we may be at the end of our allocated buffer now */
+ if(i >= current_size) {
+ char *new = realloc(line, current_size * 2);
+ if(new) {
+ line = new;
+ current_size *= 2;
+ } else {
+ free(line);
+ line = NULL;
+ break;
+ }
}
}
}
- }
- /* check for memory exhaustion */
- if(!line) {
- pm_printf(ALPM_LOG_ERROR, _("memory exhausted in argument parsing\n"));
- cleanup(EXIT_FAILURE);
- }
- /* end of stream -- check for data still in line buffer */
- if(i > 0) {
- line[i] = '\0';
- pm_targets = alpm_list_add(pm_targets, strdup(line));
- }
- free(line);
- if(!freopen(ctermid(NULL), "r", stdin)) {
- pm_printf(ALPM_LOG_ERROR, _("failed to reopen stdin for reading: (%s)\n"),
- strerror(errno));
+ /* check for memory exhaustion */
+ if(!line) {
+ pm_printf(ALPM_LOG_ERROR, _("memory exhausted in argument parsing\n"));
+ cleanup(EXIT_FAILURE);
+ }
+
+ /* end of stream -- check for data still in line buffer */
+ if(i > 0) {
+ line[i] = '\0';
+ pm_targets = alpm_list_add(pm_targets, strdup(line));
+ }
+ free(line);
+ if(!freopen(ctermid(NULL), "r", stdin)) {
+ pm_printf(ALPM_LOG_ERROR, _("failed to reopen stdin for reading: (%s)\n"),
+ strerror(errno));
+ }
+ } else {
+ /* do not read stdin from terminal */
+ pm_printf(ALPM_LOG_ERROR, _("argument '-' specified without input on stdin\n"));
+ cleanup(1);
}
}