Skip to content

Creat() ignores 0777 Mode & Fails to Reflect Permission Changes via chmod/fchmod #331

@thiru-mcw

Description

@thiru-mcw

Description

When using creat() with mode 0777 in a program compiled with aarch64-pc-cygwin-gcc, the created file ends up having default permissions set to 0644 instead of the expected 0777.

  • Attempts to modify the file's permissions using chmod() or fchmod() also do not succeed in changing the mode, even though these function calls return success (i.e., they do not report any error).
  • This issue appears to be specific to the Cygwin ARM64 environment, as the same code behaves correctly when compiled with linux-gcc, where the file is created with the specified 0777 permissions and chmod() functions as expected.
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
 
int main() {
    const char *filename = "testfile.txt";
 
    int fd = creat(filename, 0777);
 
    if (fd == -1) {
        printf("creat failed");
        return 1;
    } else {
        printf("File '%s' created successfully with fd = %d\n", filename, fd);
    }
 
    if (chmod(filename, 0777) == -1) {
        printf("chmod failed");
        return 1;
    } else {
        printf("File mode changed to 0777 using chmod\n");
    }
 
    struct stat st;
    if (stat(filename, &st) == -1) {
        printf("stat failed");
        return 1;
    }
 
    printf("File '%s' access mode: %o (octal)\n", filename, st.st_mode & 0777);
 
    return 0;
}
 

Output of aarch64-pc-cygwin-gcc

File 'testfile.txt' created successfully with fd = 3
File mode changed to 0777 using chmod
File 'testfile.txt' access mode: 644 (octal)

Output of linux gcc

File 'testfile.txt' created successfully with fd = 3
File mode changed to 0777 using chmod
File 'testfile.txt' access mode: 777 (octal)

Acceptance Criteria:

  1. The creat function must successfully create a file with permission mode 0777.
  2. The file’s permissions must be changeable using fchmod or chmod, and the updated mode should be correctly applied and reflected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions