freopen() broken in Fedora 15

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The standard IO freopen function stopped working on or about
the time I installed 64 bit Fedora 15 on the omen.com server.

The attached program is derived from the 1977 Bill Joy version.
It does not display any text when compiled and run under 64 bit
F 15 clean install and updated as of today.

The workaround is to rewrite the program to eliminate the use
of freopen.

--
Chuck Forsberg WA7KGX N2469R     caf@xxxxxxxx   www.omen.com
Developer of Industrial ZMODEM(Tm) for Embedded Applications
  Omen Technology Inc      "The High Reliability Software"
10255 NW Old Cornelius Pass Portland OR 97231   503-614-0430

#ifndef	lint
static char *sccsid = "@(#)head.c	4.1 (Berkeley) 10/1/80";
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/*
 * head - give the first few lines of a stream or of each of a set of files
 *
 * Bill Joy UCB August 24, 1977
 */

int	linecnt	= 10;
char Intorev[] = "\033[7m";
char Outarev[] = "\033[0m";
int totty = 0;

main(Argc, argv)
register int Argc;
register char *argv[];
{
	register int argc;
	char *name;
	static int around;
	char obuf[BUFSIZ];
	register c;
	struct stat f;

	setbuf(stdout, obuf);
	totty = isatty(1);
	Argc--, argv++;
	argc = Argc;
	if (Argc)
		linecnt = 20/Argc;
	if (linecnt < 2)
		linecnt = 2;
	do {
		while (argc > 0 && argv[0][0] == '-') {
			linecnt = getnum(argv[0] + 1);
			argc--, argv++, Argc--;
		}
		if (argc == 0 && around)
			break;
		if (argc > 0) {
			close(0);
			if (freopen(argv[0], "r", stdin) == NULL) {
				perror(argv[0]);
				exit(1);
			}
			name = argv[0];
			argc--, argv++;
			fstat(fileno(stdin), &f);
			c = f.st_mode & S_IFMT;
			if (c == S_IFDIR)
				continue;
		} else
			name = 0;
/*
		if (around && !totty)
			putchar('\n');
*/
		around++;
		if (Argc > 1 && name) {
			if (totty)
				printf("%s%s%s ",
				  Intorev, name, Outarev);
			else
				printf("%s ", name);
		}
		copyout(linecnt);
		fflush(stdout);
	} while (argc > 0);
}

copyout(cnt)
register int cnt;
{
	char lbuf[BUFSIZ];
	int l;
	int lines = 0;

	while (cnt > 0 && fgets(lbuf, sizeof lbuf, stdin) != 0) {
		printf("%s", lbuf);
		l = strlen(lbuf);
		if ((l > 1) && iscntrl(lbuf[l-1]))
			++lines;
		fflush(stdout);
		cnt--;
	}
	if (lines == 0)
		putchar('\n');
}

getnum(cp)
register char *cp;
{
	register int i;

	for (i = 0; *cp >= '0' && *cp <= '9'; cp++)
		i *= 10, i += *cp - '0';
	if (*cp) {
		fprintf(stderr, "Badly formed number\n");
		exit(1);
	}
	return (i);
}
-- 
test mailing list
test@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe: 
https://admin.fedoraproject.org/mailman/listinfo/test

[Index of Archives]     [Fedora Desktop]     [Fedora SELinux]     [Photo Sharing]     [Yosemite Forum]     [KDE Users]

  Powered by Linux