From owner-freebsd-questions@FreeBSD.ORG Tue Jul 28 04:54:52 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A968D1065672 for ; Tue, 28 Jul 2009 04:54:52 +0000 (UTC) (envelope-from unga888@yahoo.com) Received: from web57002.mail.re3.yahoo.com (web57002.mail.re3.yahoo.com [66.196.97.106]) by mx1.freebsd.org (Postfix) with SMTP id 4E4038FC12 for ; Tue, 28 Jul 2009 04:54:52 +0000 (UTC) (envelope-from unga888@yahoo.com) Received: (qmail 70282 invoked by uid 60001); 28 Jul 2009 04:54:51 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1248756891; bh=9/NBufaPY4aPzZxQM5PGNNvzeavJGIqyyOoI5nnLagY=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=MaDIgmk+lrTh2faotBF+si/bA5Wcl8XuP3dXDUH68lg9n6PNXV+jnf11XpqMtcLM+z4NFj57Ui42G/E1XjL1tfDS5I29P+lzWuuDjFBxuqUxvX3Ui5lT+kRVkfhZGok3/Mx1xKOWbd6tQT0ZoyKQ2G6xJLnm0Zue+2kSzA2578I= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=rURnHPJWtCCfdP+4SOfs/rvBFMzFsqduCPR68s0uiuF7NmDhuh5eZFS2jvNtz2sMeGKumjFhMWXG+UaSVRbqpvYOmrh7dxe2dWFVENm9WA7g1eCWgFJfMeD5BfpFMJm+LdConQIrlXLIThZwEmf79oLAMxZIzXIh1pPN5kFx74g=; Message-ID: <631612.70113.qm@web57002.mail.re3.yahoo.com> X-YMail-OSG: cXU6aLMVM1lW67QCqvvS_mpIo2QNJmFmmli9z9l1HulbTDlPBmygmu9llwGNSdikPLrxRiWN1wU5Al519JNU_O3gJdrpghyqwnzQ1Gh0VpWQnxjTcPmJukp1fkgrX8pabPPC3WMnPZ2e5HovLoP89QGxZOCpcfeB9xK44egmdm8COMabdal2GyCyTZsBVlEJ.wp6m5ao7h5onSGoVTOBIk6ZSZWUCRbNqsxozHVDRbHzqWGDVWkI62.b2Dd_QqjTlOhllCFpuzNNRaVrm_EUmjxLmagzDejjh_qyd0yXj_X9cwrJFK70WRXM0oAt0MPJDX_CVLPiuclfoihZvGI- Received: from [220.255.7.138] by web57002.mail.re3.yahoo.com via HTTP; Mon, 27 Jul 2009 21:54:51 PDT X-Mailer: YahooMailClassic/5.4.17 YahooMailWebService/0.7.289.15 Date: Mon, 27 Jul 2009 21:54:51 -0700 (PDT) From: Unga To: freebsd-questions@freebsd.org, Mel Flynn MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Subject: Re: How to find what symlink points to? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Jul 2009 04:54:52 -0000 --- On Tue, 7/28/09, Mel Flynn wrote: > From: Mel Flynn > Subject: Re: How to find what symlink points to? > To: freebsd-questions@freebsd.org > Date: Tuesday, July 28, 2009, 1:25 AM > On Monday 27 July 2009 05:45:13 Unga > wrote: >=20 > > > > Hi all > > > > > > > > I need to remove some unwanted symlinks on > /dev using > > > > > > a C program. > > > > > > > The "struct dirent" only shows the symlink > name, how > > > > > > do I find what that > > > > > > > symlink points to for verification purpose? > > > > > > By using the readlink(2) system call. > > > > But readlink(2) fails with errno set to 2. Can > readlink(2) use with dev > > nodes? >=20 > Works for me. errno 2 is ENOENT ("No such file or > directory"). I would inspect=20 > if your request path points to the right location. >=20 > % ./rl /dev/stderr > /dev/stderr =3D> fd/2 >=20 > % cat rl.c > #include > #include > #include > #include > #include > #include >=20 > #include >=20 > int main(int argc, char **argv) > { > =A0 =A0 =A0 =A0 char path[MAXPATHLEN], > buf[MAXPATHLEN+1]; > =A0 =A0 =A0 =A0 ssize_t res; >=20 > =A0 =A0 =A0 =A0 if( argc !=3D 2 ) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 > exit(67); >=20 > =A0 =A0 =A0 =A0 (void)strlcpy(path, argv[1], > sizeof(path)); > =A0 =A0 =A0 =A0 res =3D readlink(path, buf, > sizeof(buf)); > =A0 =A0 =A0 =A0 if( res < 0 ) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 > err(EXIT_FAILURE, "readlink()"); > =A0 =A0 =A0 =A0 buf[MAXPATHLEN] =3D '\0'; > =A0 =A0 =A0 =A0 printf("%s =3D> %s\n", path, > buf); >=20 > =A0 =A0 =A0 =A0 return (0); > } >=20 Thanks everybody for valuable replies. In fact, I also used readlink(2) but= fed the symlink path directly from dirent, which was partial, readlink(2) = requires full path. Unga=0A=0A=0A