LINUX.ORG.RU

Почему макросы major, minor возвращают странные значения?


0

1

Есть код:

$ cat t.c
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

int main()
{
        struct stat st;
        const char *s = "/dev/input/event0";
#ifdef _BSD_SOURCE
        printf("_BSD_SOURCE is defined.\n");
#else
        printf("_BSD_SOURCE is NOT defined.\n");
#endif
        if (stat(s, &st) == 0) {
                printf("ID: %lld\n", st.st_dev);
                printf("%s: char dev=%s, major=%u, minor=%u\n",
                   s, S_ISCHR(st.st_mode) ? "yes" : "no", major(st.st_dev), minor(st.st_dev));
        } else
                printf("Err: \n");
        return 0;
}
Компилирую:
$ gcc -Wall -ggdb -O2 t.c -o t
Запускаю:
$ ./t 
_BSD_SOURCE is defined.
ID: 5
/dev/input/event0: char dev=yes, major=0, minor=5
А в консоли:
$ ls -la /dev/input/event0
crw------- 1 root root 13, 64 Jun 15 08:49 /dev/input/event0
Почему major, minor в программе возвращают странные значения?
$ uname -r
2.6.32-5-686
$ gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-8' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-targets=all --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.4.5 (Debian 4.4.5-8)


Ответ на: комментарий от anonymous

Блиииииииин. Точно. Спасибо!

Всё! Пора идти спать.

Dennis7
() автор топика
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.