Vin*_*ura 10
要阅读粘滞位使用stat()检查.st_mode的S_ISVTX
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
struct stat file_stats;
stat("my_file", &file_stats);
if (file_stats.st_mode & S_ISVTX)
printf("sticky\n");
Run Code Online (Sandbox Code Playgroud)
重置它,你通过 chmod
struct stat file_stats;
stat("my_file", &file_stats);
mode_t new_mode = file_stats.st_mode & ~S_ISVTX;
chmod("my_file", new_mode);
Run Code Online (Sandbox Code Playgroud)
设置它,chmod它是
struct stat file_stats;
stat("my_file", &file_stats);
mode_t new_mode = file_stats.st_mode | S_ISVTX;
chmod("my_file", new_mode);
Run Code Online (Sandbox Code Playgroud)
此代码未经测试.