From owner-freebsd-hackers@FreeBSD.ORG Wed Jun 13 15:58:45 2007 Return-Path: X-Original-To: hackers@freebsd.org Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 5D74C16A4E6 for ; Wed, 13 Jun 2007 15:58:45 +0000 (UTC) (envelope-from gshapiro@freebsd.org) Received: from gir.gshapiro.net (gir.gshapiro.net [209.246.26.16]) by mx1.freebsd.org (Postfix) with ESMTP id 39D2A13C4B0 for ; Wed, 13 Jun 2007 15:58:45 +0000 (UTC) (envelope-from gshapiro@freebsd.org) Received: from monkeyboy.local (c-67-164-3-230.hsd1.ca.comcast.net [67.164.3.230]) (authenticated bits=128) by gir.gshapiro.net (8.14.1/8.14.1) with ESMTP id l5DFc0rI085586 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 13 Jun 2007 08:38:02 -0700 (PDT) (envelope-from gshapiro@freebsd.org) X-DKIM: Sendmail DKIM Filter v1.0.0 gir.gshapiro.net l5DFc0rI085586 X-DomainKeys: Sendmail DomainKeys Filter v0.6.0 gir.gshapiro.net l5DFc0rI085586 Date: Wed, 13 Jun 2007 08:37:46 -0700 From: Gregory Shapiro To: Garrett Cooper Message-ID: <20070613153745.GF27029@monkeyboy.local> References: <466F86C6.7010006@u.washington.edu> <20070613123213.GE98927@bunrab.catwhisker.org> <46700CAE.6020902@u.washington.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <46700CAE.6020902@u.washington.edu> User-Agent: Mutt/1.5.15 (2007-04-06) Cc: hackers@freebsd.org Subject: Re: Using shell commands versus C equivalents 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, 13 Jun 2007 15:58:45 -0000 > Sorry -- actually I meant that (along similar lines), there was a program > with the following lines: > > vsystem("/bin/chmod +x %s", filename); > > and I replaced it with: > > chmod(filename, (mode_t) ( S_IXUSR | S_IXGRP | S_IXOTH )); Those two lines have different effects. The first adds the execute bit to the file. The second replaces the current permissions with only the execute bit. To have the same affect, you need to stat() the file, and then use bitwise-or to add the S_IXUSR | S_IXGRP | S_IXOTH bits to st_mode and use that new st_mode with chmod().