What is the purpose of using double underscore (__) before and after the filename in c?

I am learning the Android kernel as a newbie. I can read messages thrown from a macro ERROR()inside a function main()in system/core/init/init.cusing the command dmesgvia adb. I noticed that after calling the function open_devnull_stdio()inside main(), it dmesgno longer displays messages sent ERROR().

To find the reason, I started digging into the declaration open_devnull_stdio()inside system/core/init/util.c, and I found this line, which I cannot understand

static const char *name = "/dev/__null__";

Actually, the device did not have a file with a name __null__inside /dev/, but there was a file with a name null, and I was able to capture it with adb pulland it was a 0-byte (empty) file.

So why is the file name wrapped in double underscore (__)?

Here is the link for util.c

+4
source share
3 answers

There is no particular purpose of using double underscores before starting, after ending, or both in C. From the point of view of C, the file name is just a string, the operating system is free to interpret in whatever way it chooses. From a Linux perspective, the same thing. Underscores for files are just characters. They are not processed otherwise than the letters band t.

, , ( ), , , . :

if (mknod(name, S_IFCHR | 0600, (1 << 8) | 3) == 0) {
    fd = open(name, O_RDWR);
    unlink(name);

, .

, , /dev/null.

+2

, :

"strace", /dev/__null__:

https://gist.github.com/tetsu-koba/1522515

Linux 33- (?) , . ( , Linux) /dev, (!), 33- ! ( , /dev/sda2 ( !) /home/myuser/sda2.)

:

mknod("/dev/__null__", S_IFCHR|0600, makedev(1, 3)) = 0
open("/dev/__null__", O_RDWR|O_LARGEFILE) = 3
unlink("/dev/__null__") = 0

/dev/__null__ ( 33- , /dev/null). , .

, , Linux, "/dev/null" ( ) , ( 33- ).

+2

, " ", "null". null , , . , .

-1

Source: https://habr.com/ru/post/1684716/


All Articles