Pagina 1 di 1

System call

Inviato: ven 16 mar 2007, 21:15
da doping
Ho il seguente problema:
ciro@w7j:~/Desktop$ gcc -o esercizio.out Exercise-1.c
Exercise-1.c: In function 'main':
Exercise-1.c:20: error: 'S_IRUSR' undeclared (first use in this function)
Exercise-1.c:20: error: (Each undeclared identifier is reported only once
Exercise-1.c:20: error: for each function it appears in.)
Exercise-1.c:20: error: 'S_IWUSR' undeclared (first use in this function)
Exercise-1.c:20: error: 'S_IRGRP' undeclared (first use in this function)
Exercise-1.c:20: error: 'S_IROTH' undeclared (first use in this function)
Sono i miei primi passi nella programmazzione linux in C!però non capisco perchè quelle costanti non le riconosce..manca qualche libreria per caso??ecco il sorgente nella sua parte iniziale:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)

int main(void)
{

int fd, i, j;
off_t offset_store;
off_t offset;
char *buff, c;
char string_num[10] = "1234567890";
char string_Let[10] = "abcdefghil";

buff = calloc(25, sizeof(char));

if((fd = open("FILE1", (O_RDWR | O_APPEND | O_CREAT | O_TRUNC),FILE_MODE)) <0)
printf("\n an error occurred opening the file\n");

Inviato: ven 16 mar 2007, 21:25
da michele.p
..le costanti che hai indicato le hai definite tu oppure sono implementate in qualche file .h del kernel?...e se si, quale?

Bye

Inviato: ven 16 mar 2007, 21:43
da doping
Diciamo che all'università il Prof ci ha spiegato il loro significato, ma non dove erano definite, comunque ho trovato l'header, è <sys/stat.h>, adesso funziona tutto...però sono sicuro che il prof questo .h non lo ha usato..

Inviato: sab 17 mar 2007, 1:57
da useless
Probabilmente aveva solo un'altra versione di gcc/glibc/linux. Non ti fare troppi problemi, includi sys/stat.h e vai tranquillo :).

comunque, quando hai di questo dubbi: man open, e ti dice cosa devi includere.