Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 15 Dec 2005 16:47:17 -0500
From:      Nicolas Blais <nb_root@videotron.ca>
To:        freebsd-questions@freebsd.org
Cc:        Vasilkov Vasily <chand0s@list.ru>
Subject:   Re: "fopen" call...
Message-ID:  <200512151647.23500.nb_root@videotron.ca>
In-Reply-To: <op.s1ug66y1fi920b@lazy.lazy.org>
References:  <op.s1ug66y1fi920b@lazy.lazy.org>

next in thread | previous in thread | raw e-mail | index | archive | help
--nextPart2866146.lKyPuEgPZ5
Content-Type: text/plain;
  charset="koi8-r"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On December 15, 2005 04:41 pm, Vasilkov Vasily wrote:
> Hi all..
>     this is the part of my source
> ************
>     FILE *source;
>     source =3D fopen("/home/user/test.c", "r");
>     if (source) {
>       printf("fopen error");
>       exit(0);
>     };
> ************
>   file "/home/user/test.c" exists and its access mode is 777..., but
>   when I run program, I get "fopen error" message...
>
>   Can anybody explain me this subj?
>
>

=46rom man fopen:

RETURN VALUES
     Upon successful completion fopen(), fdopen() and freopen() return a FI=
LE
     pointer.  Otherwise, NULL is returned and the global variable errno is
     set to indicate the error.

That means that your code should be:

     FILE *source;
     source =3D fopen("/home/user/test.c", "r");
     if (!source) {
       printf("fopen error");
       exit(0);
     };

Nicolas.

=2D-=20
=46reeBSD 7.0-CURRENT #4: Sat Dec 10 11:55:08 EST 2005    =20
root@clk01a:/usr/obj/usr/src/sys/CLK01A=20
PGP? (updated 16 Nov 05) : http://www.clkroot.net/security/nb_root.asc

--nextPart2866146.lKyPuEgPZ5
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (FreeBSD)

iD8DBQBDoeRr4wTBlvcsbJURAhYkAJwP3VrufI45tVFXGiAemoqfSwwX6wCeOY7t
JqbY/KlBLBHsKnCnZCPgPKE=
=QBzA
-----END PGP SIGNATURE-----

--nextPart2866146.lKyPuEgPZ5--



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