vfs is correct. You need the leading zero on the mode. You should use the macros that are defined in the headers. To get 777 permissions you could use:
Code:
(S_IRWXU | S_IRWXG | S_IRWXO)
Remember that the shells umask value may cancel out some permissions when the file is created, so may get something that you don't expect.
Also you can use creat( "", mode) instead of open( "", O_CREAT|O_WRONLY|O_TRUNC, mode ) when creating files.
Code:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define FILEMODE (S_IRWXU | S_IRWXG | S_IRWXO)
main()
{
int fd = 0;
ssize_t iWrite = 0;
char szBuf[] = "Hello there";
fd = open( "tempfile",
O_CREAT|O_WRONLY|O_TRUNC,
FILEMODE );
iWrite = write ( fd, szBuf, sizeof( szBuf ) );
close ( fd );
}