Portál AbcLinuxu, 12. května 2025 08:00

Dotaz: funkce stat()

22.3.2008 14:29 macikmorin
funkce stat()
Přečteno: 373×
Odpovědět | Admin
Dobry den, chtel jsem si vyzkouset funkci stat() na zjisteni informaci o souboru. Zadal jsem tedy do konzole man 2 stat a otevrela se mi manualova stranka teto funkce. Zde se taky nachazi priklad pouziti (EXAMPLE). Cely tento program jsem si zkopiroval do souboru a zkusil ho prelozit. GCC mi vsak zahlasilo tyto chyby:
make
gcc -std=c99 -pedantic -Wall -W -g -c linux.c
linux.c: In function ‘main’:
linux.c:26: error: ‘S_IFMT’ undeclared (first use in this function)
linux.c:26: error: (Each undeclared identifier is reported only once
linux.c:26: error: for each function it appears in.)
linux.c:27: error: ‘S_IFBLK’ undeclared (first use in this function)
linux.c:28: error: ‘S_IFCHR’ undeclared (first use in this function)
linux.c:29: error: ‘S_IFDIR’ undeclared (first use in this function)
linux.c:30: error: ‘S_IFIFO’ undeclared (first use in this function)
linux.c:31: error: ‘S_IFLNK’ undeclared (first use in this function)
linux.c:32: error: ‘S_IFREG’ undeclared (first use in this function)
linux.c:33: error: ‘S_IFSOCK’ undeclared (first use in this function)
make: *** [linux.o] Error 1
Vsechny tyto konstanty by se podle me meli nachazet v /sys/stat.h knihovne, ta je vsak v programu includovana (viz onen exapmle z dokumentace). Co je tedy spatne?
Nástroje: Začni sledovat (1) ?Zašle upozornění na váš email při vložení nového komentáře.

Odpovědi

22.3.2008 16:18 Messa | skóre: 39 | blog: Messa
Rozbalit Rozbalit vše Re: funkce stat()
Odpovědět | | Sbalit | Link | Blokovat | Admin
Zkuste si pohrát s parametry spouštěného gcc. Nejspíše je na vině -std=c99. Nicméně proč zrovna to vadí nevím.
22.3.2008 17:41 petris
Rozbalit Rozbalit vše Re: funkce stat()
Odpovědět | | Sbalit | Link | Blokovat | Admin
Kdybyste si ten man přečetl celý, tak je to tam vysvětlené:
POSIX does not describe the S_IFMT, S_IFSOCK, S_IFLNK, S_IFREG, S_IFBLK, S_IFDIR, S_IFCHR, S_IFIFO, S_ISVTX bits, but instead demands the use of the macros S_ISDIR(), etc. The S_ISLNK() and S_ISSOCK() macros are not in POSIX.1-1996, but both are present in POSIX.1-2001; the former is from SVID 4, the latter from SUSv2.
Použijte buď std=gnu99 nebo si zjistěte, kde jsou definována ta POSIXová makra a použijte ta.

Založit nové vláknoNahoru

Tiskni Sdílej: Linkuj Jaggni to Vybrali.sme.sk Google Del.icio.us Facebook

ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.