Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 16 Apr 2012 17:03:00 -0500 From: "Joe Shead" Newsgroups: comp.os.linux.development.apps Subject: fopen() of a read-only file for writing? Date: Mon, 16 Apr 2012 17:03:13 -0600 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_008C_01CD1BF2.CF1296F0" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.2001 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.2001 Message-ID: Lines: 99 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.230.120.211 X-Trace: sv3-5gekQCaRLVvGEnFtdGplbSXPwDonk22i/F2w0MWabEh2U2W4p0FQ6wDaGOkXxDZz+znkGKzmFfYgp5o!96rAqaERZhq6KH7dt2eGaWJpyCd807vap+/TKBhdlMe8bJHzfkcPHkrVDAVkWk3OsEJzsB1J99qB!6rxppw7LNNHjW2mSCN3GMPuGo2rd/84xVQ== X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 4500 Xref: csiph.com comp.os.linux.development.apps:458 This is a multi-part message in MIME format. ------=_NextPart_000_008C_01CD1BF2.CF1296F0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, I have a file that has no write permissions on it, called readonly.txt. = I am logged on as root. ls -l returns the line: -r-xr--r-- 1 root root 32 Apr 15 20:20 readonly.txt I do: int errnos[4]; FILE *f=3D0; errno=3D0; errnos[0]=3Derrno; f=3Dfopen("readonly.txt", "wb"); errnos[1]=3Derrno; if (f!=3D0){ putc('a', f); errnos[2]=3Derrno; fclose(f); f=3D0; errnos[3]=3Derrno;} I get a non-zero f from fopen(), the putc() works, and all 4 errnos are = 0. After executing this code, the file is 1 byte long with just the 'a' = in it. Is this behavior correct? I'm really not sure, but if someone could explain it to me, or direct me = to the right people to talk to, that would help. It seems like fopen() = ought to return 0, and set errno to EACCES. I built my version of linux using lfs (linux from scratch). I'm using = linux kernel version 2.4.21, gcc version 3.2.1, and libc version 2.3.1. Thanks in advance, Joe ------=_NextPart_000_008C_01CD1BF2.CF1296F0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi,

I have = a file that=20 has no write permissions on it, called readonly.txt. I am logged on as=20 root.

ls -l returns the line:

 =20 -r-xr--r-- 1 root root   32   Apr 15 20:20=20 readonly.txt

I do:

<CODE>
    = int=20 errnos[4];
    FILE *f=3D0;

   =20 errno=3D0;
    = errnos[0]=3Derrno;
   =20 f=3Dfopen("readonly.txt", "wb");
   =20 errnos[1]=3Derrno;
    if=20 (f!=3D0){
        putc('a',=20 f);
       =20 errnos[2]=3Derrno;
        = fclose(f);=20 f=3D0;
       =20 errnos[3]=3Derrno;}
</CODE>

I get a non-zero f = from=20 fopen(), the putc() works, and all 4 errnos are 0. After executing this = code,=20 the file is 1 byte long with just the 'a' in it.

Is this behavior = correct?

I'm really not sure, but if someone could explain it to = me, or=20 direct me to the right people to talk to, that would help. It seems like = fopen()=20 ought to return 0, and set errno to EACCES.

I built my version of = linux=20 using lfs (linux from scratch). I'm using linux kernel version 2.4.21, = gcc=20 version 3.2.1, and libc version 2.3.1.

Thanks in=20 advance,

Joe ------=_NextPart_000_008C_01CD1BF2.CF1296F0--