bin/77031: [patch] comm(1) unable to handle lines greater than
LINE_MAX (2048)
Giorgos Keramidas
keramida at ceid.upatras.gr
Fri Feb 4 13:21:00 PST 2005
On 2005-02-04 21:16, Mario Hoerich <lists at MHoerich.de> wrote:
> # Fergus Cameron:
> > http://people.freebsd.org/~keramida/fergus/comm.c-diff
>
> Now to your patch. What I've noticed while doing a preliminary
> review (bit short on time right now) was:
>
> file1 = file( argv[0] ) ;
> file2 = file( argv[1] ) ;
>
> if( file1 == file2 )
> errx(EXIT_FAILURE, "cannot match file against self");
>
> You sure this is guaranteed to trigger? I'm not standard-
> savvy enough to know for sure, but it seems like a potential
> problem. Anyone with a definitive answer?
It is not guaranteed by any standard that I know of. A small sample
program like the following shows it is, in fact, not going to work on
FreeBSD:
% #include <err.h>
% #include <stdio.h>
%
% int
% main(int argc, char *argv[0])
% {
% FILE *fp, *fp2;
%
% if (argc != 2)
% errx(1, "usage: foo FILENAME");
% fp = fopen(argv[1], "r");
% if (fp == NULL)
% err(1, "fopen: %s", argv[1]);
% fp2 = fopen(argv[1], "r");
% if (fp2 == NULL) {
% fclose(fp);
% err(1, "fopen: %s", argv[1]);
% }
% printf("%p\n%p\n", fp, fp2);
% fclose(fp);
% fclose(fp2);
% return (0);
% }
This will not print the same pointer value for fp and fp2, regardless of
the fopen() calls being passed the same filename as their first
argument:
% $ ./foo foo
% 0x28148880
% 0x281488d8
FWIW, a good way to find if two files are, indeed, pointers to the same
i-node (i.e. hard links to the same disk file) is to compare the device
major/minor numbers *AND* the i-node number.
More information about the freebsd-bugs
mailing list