I am learning C recently, and I saw that some functions use bitwise or parameter passing. I don’t know what it means, and it seems that bit operations are rarely used in daily work.
For example, the following piece of code
#define LOCKFILE "/var/run/gwyydaemon.pid"
#define LOCKMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
fd = open(LOCKFILE,O_RDWR|O_CREAT,LOCKMODE);
What do the O_RDWR|O_CREAT and S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH here mean?
You need to check the documentation yourself
O_RDWR
: Readable and writableO_CREAT
: If the file does not exist, create itBitwise OR means combined configuration, assuming (I don’t know the specific value):
O_RDWR
等于二进制00000001
O_CREAT
等于二进制00000010
is equal to binary00000001
O_CREAT
is equal to binary00000010
It’s just bit operations
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH and so on should be defined in a certain header file
For example (the value is written casually by me, please check that header file for details, I’m being lazy)
Wait.