From owner-freebsd-hackers@FreeBSD.ORG Wed May 12 21:30:43 2010 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 693AB106566B for ; Wed, 12 May 2010 21:30:43 +0000 (UTC) (envelope-from yanefbsd@gmail.com) Received: from mail-qy0-f190.google.com (mail-qy0-f190.google.com [209.85.221.190]) by mx1.freebsd.org (Postfix) with ESMTP id 1F4CF8FC1D for ; Wed, 12 May 2010 21:30:42 +0000 (UTC) Received: by qyk28 with SMTP id 28so555863qyk.27 for ; Wed, 12 May 2010 14:30:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:content-type :content-transfer-encoding:subject:date:message-id:to:mime-version :x-mailer; bh=ZiGg2Kx31P3paT/mV+lnF3Jdj7d7WhnJ7kOciqy6Ws4=; b=qVI4NphdBswgLJvDg+T/bMOuZ1ne2yXz1RtxT2H3H2YsL6j2jfIgv9G+mPqfrDFdSK rHmkhrcw3mLKXJj56CDLPjIr/t2nYSynqlmBCOOQAob/nsGq2WQzUqWE9uuRmd96ImtO HQDcEvqs0M8UcawCf8iU0Pi0mnpcuNcPBhXgc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:content-type:content-transfer-encoding:subject:date:message-id :to:mime-version:x-mailer; b=tyzXvTZ5TWAk2EjqgSeuvrN01bZjpg1n/gjkREhHHP9dBb+iVdvYuD8w4gFTt8PbsL /GIS7powcChl59Spgu10Q4VXu2mdVyUJstNckHeFFmFLXuxCOe5zUPd7fWLDa3ZxmBJ0 EmCWosNMWY1lim7dJAXjdE4VLh09DVoxK9+uA= Received: by 10.229.226.135 with SMTP id iw7mr5236619qcb.63.1273699842289; Wed, 12 May 2010 14:30:42 -0700 (PDT) Received: from [172.24.100.15] ([192.75.139.254]) by mx.google.com with ESMTPS id bv23sm228894qcb.7.2010.05.12.14.30.36 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 12 May 2010 14:30:38 -0700 (PDT) From: Garrett Cooper Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Date: Wed, 12 May 2010 17:30:48 -0400 Message-Id: To: hackers@freebsd.org Mime-Version: 1.0 (Apple Message framework v1078) X-Mailer: Apple Mail (2.1078) Cc: Subject: argv offset -- doesn't make sense... X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 May 2010 21:30:43 -0000 Hi Hackers, Ignoring the compiler warning (yes, I know...), why is the = offset for the argv[0] (program name) in the following program off by = one? It doesn't make sense why the fstat would work, but the printf = would fail (and in fact segfault if I remove the 1 < argc guard = statement and adjusted the offset by removing the +1). Thanks, -Garrett PS I know I'm missing all of the real error checks because I just wanted = a quick and dirty test app. # gcc -Wall -O0 -g -o test_fstat test_fstat.c test_fstat.c: In function 'main': test_fstat.c:20: warning: format '%lu' expects type 'long unsigned int', = but argument 3 has type 'off_t' # ./test_fstat ./test_fstat argc - 2, argv[0] - ./test_fstat (null) - 7118 # ./test_fstat ./test_fstat argc - 2, argv[0] - ./test_fstat ./test_fstat - -790036480 # cat test_fstat.c #include #include #include #include int main(int argc, char **argv) { if (1 < argc) { printf("argc - %d, argv[0] - %s\n", argc, *argv); int fd =3D open(*(argv+1), O_RDONLY); struct stat *sb; fstat(fd, sb); printf("%s - %ld\n", *(argv+1), (long int) sb->st_size); } return 0; }=