All of lore.kernel.org
 help / color / mirror / Atom feed
* File open/create attibutes.
@ 2002-05-14 15:44 Richard B. Johnson
  2002-05-14 16:20 ` Andreas Schwab
  2002-05-14 16:43 ` Alan Cox
  0 siblings, 2 replies; 3+ messages in thread
From: Richard B. Johnson @ 2002-05-14 15:44 UTC (permalink / raw)
  To: Linux kernel

Hello,

If a file exists with attributes, 0644, and it is opened with truncate
and create with different attributes, it doesn't get those attributes.
It's only if the file doesn't exist at all that it gets created with
the new attributes.

I think this is a bug. According to my reading, O_CREAT opens the file
with the specified attributes. If the file exists, its data remains
unless O_TRUNC is set.

The following program clearly shows the problem:


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
int main(void);
char fname[]="/tmp/foo";
int main()
{
    int fd;
    (void)unlink(fname);
    if((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1)
    {
        fprintf(stderr, "Can't create file %s\n", fname);
        exit(EXIT_FAILURE);
    }
    (void)close(fd);
    (void)system("ls -la /tmp/foo");
    if((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0744)) == -1)
    {
        fprintf(stderr, "Can't create file %s\n", fname);
        exit(EXIT_FAILURE);
    }
    (void)close(fd);
    (void)system("ls -la /tmp/foo");
    (void)unlink(fname);
    if((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0744)) == -1)
    {
        fprintf(stderr, "Can't create file %s\n", fname);
        exit(EXIT_FAILURE);
    }
    (void)system("ls -la /tmp/foo");
    (void)unlink(fname);
    return 0;
}


Cheers,
Dick Johnson

Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).

                 Windows-2000/Professional isn't.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-05-14 16:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-05-14 15:44 File open/create attibutes Richard B. Johnson
2002-05-14 16:20 ` Andreas Schwab
2002-05-14 16:43 ` Alan Cox

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.