- } else {
- int need_headers = ((argc - i) > 1);
-
- for (; i < argc; i++) {
- FILE *src;
-
- src = fopen(argv[i], "r");
- if (!src) {
- errorMsg("%s: %s\n", argv[i], strerror(errno));
- } else {
- /* emulating GNU behaviour */
- if (need_headers) {
- fprintf(stdout, "==> %s <==\n", argv[i]);
- }
- head(len, src);
- if (i < argc - 1) {
- fprintf(stdout, "\n");
- }
+ need_headers = optind != (argc - 1);
+ while (argv[optind]) {
+ if (strcmp(argv[optind], "-") == 0) {
+ fp = stdin;
+ argv[optind] = "standard input";
+ } else {
+ if ((fp = wfopen(argv[optind], "r")) == NULL)
+ status = EXIT_FAILURE;
+ }
+ if (fp) {
+ if (need_headers) {
+ printf("==> %s <==\n", argv[optind]);
+ }
+ head(len, fp);
+ if (errno) {
+ perror_msg("%s", argv[optind]);
+ status = EXIT_FAILURE;
+ errno = 0;