Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7191391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:43:08+00:00 2026-05-28T19:43:08+00:00

I create a file using the code below: #include <stdio.h> #include <stdlib.h> #include <sys/stat.h>

  • 0

I create a file using the code below:

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>

int main()
{
    const char* filename = "./test.out";
    int fd;
    if(-1 == (fd = open(filename, O_CREAT|O_RDWR, 0666)))
    {
        perror("Error");
        errno = 0;
    }       
    else
        puts("File opened");

    if(-1 == (close(fd)))
    {
        perror("Error");
        errno = 0;
    }
    else
        puts("File closed");

    return 0;
}

I specify the mode argument as 0666, which should grant read,write access to everyone. However, an ls -l shows

-rw-r--r-- 1 kmehta users 0 2012-01-29 16:29 test.out

As you can see, write permissions are only granted to the owner of the file. I do not know why everyone else is not granted permissions correctly. chmod a+w test.out sets the permissions correctly though.

Code compiled as gcc -Wall test.c

Specs: gcc v 4.5.0 on Opensuse 11.3 64 bit

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:43:09+00:00Added an answer on May 28, 2026 at 7:43 pm

    The mode argument to open specifies the maximum allowed permissions. The umask setting is then applied to further restrict the permissions.

    If you need to make the permissions be 0666 specifically you will need to use fchmod on the file handle after the open succeeds or use umask to set the process’ permissions mask before the open.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having this code: using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create))) { //save something here
friends, i have created custom title bar using following titlebar.xml file with code <?xml
I want to create a file using C++, but I have no idea how
I am trying to create a file using File newFile = new File(myFile); However
I would like to create .inf file (for creating .cab file) using msbuild command
I am trying to create a text file using VB.Net with UTF8 encoding, without
How can I create a .txt file using flex 3? And I want to
i am trying to use GZipStream to create a gz file using c#. my
I would like to know a way to create an XML file using MySQL
If I create a layout in CF9 using cflayout as below: <cfajaximport tags=cfform> <cflayout

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.