#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
char data [ 6 ];
main ( ) {
int len;
desc = open ( "Resultat", O_WRONLY | O_CREAT | O_EXCL, 0666 );
if ( desc != -1 ) {
len = write ( desc, &data, sizeof ( data ) );
if ( len != sizeof ( data ) )
printf ( "ERROR" );
} }
this is my code and i'm getting the error
O_WRONLY undeclared (first use in this function)
O_CREAT undeclared (first use in this function)
O_EXCL undeclared (first use in this function)
How do I fix that?
@Kevin is right. On my Arch installation, according to man fcntl.h
, you need to #include <fcntl.h>
to get access to O_WRONLY
.
To use open()
, you also need to #include <sys/stat.h>
.
I have tried this code in my machine (Ubuntu 12.0.4). But I didn't get any error messages like you got.
According to the man page of open()
you are probably missing #include <sys/stat.h>
.
Manual pages for open(2)
:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
Please verify that you have each and every one of the required includes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With