Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 Feb 2005 23:19:49 +0200
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        Mario Hoerich <lists@MHoerich.de>
Cc:        Fergus Cameron <fergus@cobbled.net>
Subject:   Re: bin/77031: [patch] comm(1) unable to handle lines greater than LINE_MAX (2048)
Message-ID:  <20050204211949.GC1041@gothmog.gr>
In-Reply-To: <20050204201622.GA29998@Pandora.MHoerich.de>
References:  <200502040930.j149UQDc043307@freefall.freebsd.org> <20050204201622.GA29998@Pandora.MHoerich.de>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2005-02-04 21:16, Mario Hoerich <lists@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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050204211949.GC1041>