From: "J.C. Wren" <jcwren@jcwren.com>
To: linux-kernel@vger.kernel.org
Subject: Bug in open() function (?)
Date: Fri, 11 Jul 2003 23:09:08 -0400 [thread overview]
Message-ID: <200307112309.08542.jcwren@jcwren.com> (raw)
In-Reply-To: <20030712024216.GA399@bouh.unh.edu>
I was playing around today and found that if an existing file is opened with
O_TRUNC | O_RDONLY, the existing file is truncated. This is contrary to the
documentation for "man 2 open". Which behavior is correct, the man page, or
what actually happens? Or wold this be considered a glibc/libc problem?
This is on a stock 2.5.74 kernel.
'man 2 open', on O_TRUNC: If the file already exists and is a regular file
and the open mode allows writing (i.e., is O_RDWR or O_WRONLY) it will be
truncated to length 0.
--John
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
int main (int argc, char **argv)
{
int fd;
if ((fd = open ("test", O_TRUNC | O_RDONLY)) == -1)
{
printf ("%d:%s\n", errno, strerror (errno));
exit (1);
}
close (fd);
exit (0);
}
[bash] cc test.c
[bash] ls -l >test
[bash] ls -l test
-rw-r--r-- 1 jcw users 195 Jul 11 23:06 test
[bash] ./a.out
[bash] ls -l test
-rw-r--r-- 1 jcw users 0 Jul 11 23:06 test
next prev parent reply other threads:[~2003-07-12 2:54 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-07-12 1:17 [PATCH] [2.5] adding ppp xon/xoff support Samuel Thibault
2003-07-12 1:30 ` Paul Mackerras
2003-07-12 2:42 ` Samuel Thibault
2003-07-12 3:09 ` J.C. Wren [this message]
2003-07-12 3:38 ` Bug in open() function (?) Andrew Morton
2003-07-12 5:11 ` Valdis.Kletnieks
2003-07-12 5:23 ` Andrew Morton
2003-07-12 6:14 ` Valdis.Kletnieks
2003-07-12 9:37 ` Andries Brouwer
2003-07-12 12:04 ` jw schultz
2003-07-12 5:39 ` J.C. Wren
2003-07-26 21:35 ` [PATCH] [2.6] adding xon/xoff support to ppp Samuel Thibault
2003-07-17 7:54 Bug in open() function (?) Michael Kerrisk
2003-07-17 10:54 ` Andries Brouwer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200307112309.08542.jcwren@jcwren.com \
--to=jcwren@jcwren.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®