[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug in mkdir(2)?



I find this difficult to believe, but I can't find any documentation to
say one way or the other. mkdir(2) takes a mode but ignores the
higher-order bits (e.g. the sticky bit). The following (simple) source
demonstrates this: 

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

int main(void)
{
    int error;

    error=umask(0);
    
    printf("Previous umask was %o\n",error);

    error=rmdir("tmpdir");
    if(0 == error)
        printf("rmdir worked OK\n");
    
    error=mkdir("tmpdir",01777);
    if(0 == error)
        printf("mkdir worked OK\n");

    if(-1 == error)
        printf("error %d [%s]\n",errno, strerror(errno));

    return 0;
}

And when run this I get

hammer:~$ ./mkdir-test 
Previous umask was 22
rmdir worked OK
mkdir worked OK
hammer:~$ ls -al tmpdir
total 15
drwxrwxrwx   2 steve    users        1024 Aug 15 19:17 ./
drwx--x--x  76 steve    users       13312 Aug 15 19:17 ../

I can use chmod to add the sticky bit just fine, but mkdir doesn't do it.
Please tell me that I'm missing something...!

-- 
Steve McIntyre, Cambridge, UK.                   stevem@chiark.greenend.org.uk
<a href=http://www.chiark.greenend.org.uk/~damerell/CUWoCS/CUWoCS.html>CUWoCS 
home page</a>                          Cthulhu - Why vote for the Lesser Evil?
"Tongue-tied & twisted, Just an earth-bound misfit, I..."  |Finger for PGP key


Reply to: