Way OT programming question

Simon Barner barner at in.tum.de
Sun Aug 1 17:39:24 PDT 2004


Josh Paetzel wrote:
> I've been muddling through some of the source files for FreeBSD 
> 5.2.1-RELEASE, and I've noticed that a large number of .c files 
> in /usr/src have something similar to below in them:
> 
> #ifndef lint
> #if 0
> static char sccsid[] = "@(#)cat.c       8.2 (Berkeley) 4/27/95";
> #endif
> #endif /* not lint */
> #include <sys/cdefs.h>
> __FBSDID("$FreeBSD: src/bin/cat/cat.c,v 1.29 2003/04/30 17:40:28 
> obrien Exp $");
> 
> 1) Isn't 'if 0' always negative?

Yes, has the same effect as using comments. I don't know why #if 0 was
used here, but the line was probably kept in order to document the
(version) history of the file.

> 2) What is the __FBSDID line doing?

It has the same purpose as the static char sccsid[] line: Each and every
source file adds an id line to the resulting binary executable. Thus it
is possible to determine the exact version of file.

Example:

% ident /bin/ls

/bin/ls:
     $FreeBSD: src/lib/csu/i386-elf/crti.S,v 1.6 2002/05/15 04:19:49 obrien Exp $
     $FreeBSD: src/lib/csu/i386-elf/crtn.S,v 1.5 2002/05/15 04:19:49 obrien Exp $
     $FreeBSD: src/lib/csu/common/crtbrand.c,v 1.4 2003/10/17 15:43:13 peter Exp $
     $FreeBSD: src/lib/csu/i386-elf/crt1.c,v 1.12 2003/01/26 23:14:47 markm Exp $
     $FreeBSD: src/bin/ls/cmp.c,v 1.12 2002/06/30 05:13:54 obrien Exp $
     $FreeBSD: src/bin/ls/ls.c,v 1.75 2003/12/01 19:10:29 obrien Exp $
     $FreeBSD: src/bin/ls/print.c,v 1.66 2003/10/16 07:07:20 tjr Exp $
     $FreeBSD: src/bin/ls/util.c,v 1.32 2003/09/09 12:02:52 tjr Exp $

Btw: ident(1) also works on source files, Makefiles -- basically
everything that has a CVS id line.

__FBSDID is defined in /usr/src/sys/sys/cdefs.h

Simon

Btw: While reading the FreeBSD source can be very interesting, browsing the
     commit logs can be even more exciting: You can either use `cvs log'
     directly (on your local copy of the repository or via anoncvs),
     or use the web interface at http://cvsweb.FreeBSD.org.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: Digital signature
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20040802/2b1dae06/attachment.bin


More information about the freebsd-questions mailing list