posix

Can I get the access mode of a `FILE*`?

喜欢而已 提交于 2021-01-27 04:39:10
问题 I have to duplicate a FILE* in C on Mac OS X (using POSIX int file descriptors all the way is unfortunately out of question), so I came up with the following function: static FILE* fdup(FILE* fp, const char* mode) { int fd = fileno(fp); int duplicated = dup(fd); return fdopen(duplicated, mode); } It works very well, except it has that small ugly part where I ask for the file mode again, because fdopen apparently can't determine it itself. This issue isn't critical, since basically, I'm just

What is the written-out word for O_EXCL

霸气de小男生 提交于 2021-01-05 09:20:06
问题 I was writing a safe enum class for the different file flags listed in open(3) , when I noticed that I couldn't find the written-out word for O_EXCL . enum class Flags { readOnly, // O_RDONLY truncate, // O_TRUNC ? // O_EXCL }; Two possible meanings come into my mind: OPEN_EXCLUSIVE OPEN_EXISTS_CLOSE But I can't find any resources on the intended meaning. 回答1: Exclusive would be a correct word here, since the flag is exclusive to the O_CREAT flag and makes the function fail if the file exists

c++11 use condition variable in signal handler

瘦欲@ 提交于 2021-01-02 05:34:05
问题 Is it safe to use std::condition_variable::notify_one in signal handler? Example: enum State { DoNot, Do, }; State state; std::mutex mutex; // worker thread std::thread th = std::thread([]() { std::unique_lock<std::mutex> lc(mutex); cv.wait(lc, []() { return state; }); }); //signal handler void handler(int sig) { if (sig == SOME_SIG) { std::unique_lock<std::mutex> lc(mutex); state = Do; cv.notify_one(); } } 回答1: A C++14 draft standard N4296 says: [support.runtime]/10 The common subset of the

c++11 use condition variable in signal handler

混江龙づ霸主 提交于 2021-01-02 05:32:08
问题 Is it safe to use std::condition_variable::notify_one in signal handler? Example: enum State { DoNot, Do, }; State state; std::mutex mutex; // worker thread std::thread th = std::thread([]() { std::unique_lock<std::mutex> lc(mutex); cv.wait(lc, []() { return state; }); }); //signal handler void handler(int sig) { if (sig == SOME_SIG) { std::unique_lock<std::mutex> lc(mutex); state = Do; cv.notify_one(); } } 回答1: A C++14 draft standard N4296 says: [support.runtime]/10 The common subset of the

jq 1.5 multiple bash variables as argument

别等时光非礼了梦想. 提交于 2020-12-15 01:50:29
问题 I'm working on a script for my openwrt, a watchdog for my pia connection. I'm trying to make this little jq filter but every time I try I get error I've more options and I "compose" the jq filter all_region_data=$(curl -s "https://serverlist.piaservers.net/vpninfo/servers/v4" | head -1) BestRegion="italy" jq_filter='.regions[]' if [ -z "$BestRegion" ]; then # BestRegion not forced if [ "$pia_pf" = "true" ]; then jq_filter="${jq_filter} | select(.port_forward==true)" fi if [ "$pia_no_geo" =

jq 1.5 multiple bash variables as argument

99封情书 提交于 2020-12-15 01:45:52
问题 I'm working on a script for my openwrt, a watchdog for my pia connection. I'm trying to make this little jq filter but every time I try I get error I've more options and I "compose" the jq filter all_region_data=$(curl -s "https://serverlist.piaservers.net/vpninfo/servers/v4" | head -1) BestRegion="italy" jq_filter='.regions[]' if [ -z "$BestRegion" ]; then # BestRegion not forced if [ "$pia_pf" = "true" ]; then jq_filter="${jq_filter} | select(.port_forward==true)" fi if [ "$pia_no_geo" =

jq 1.5 multiple bash variables as argument

寵の児 提交于 2020-12-15 01:45:41
问题 I'm working on a script for my openwrt, a watchdog for my pia connection. I'm trying to make this little jq filter but every time I try I get error I've more options and I "compose" the jq filter all_region_data=$(curl -s "https://serverlist.piaservers.net/vpninfo/servers/v4" | head -1) BestRegion="italy" jq_filter='.regions[]' if [ -z "$BestRegion" ]; then # BestRegion not forced if [ "$pia_pf" = "true" ]; then jq_filter="${jq_filter} | select(.port_forward==true)" fi if [ "$pia_no_geo" =

jq 1.5 multiple bash variables as argument

佐手、 提交于 2020-12-15 01:45:30
问题 I'm working on a script for my openwrt, a watchdog for my pia connection. I'm trying to make this little jq filter but every time I try I get error I've more options and I "compose" the jq filter all_region_data=$(curl -s "https://serverlist.piaservers.net/vpninfo/servers/v4" | head -1) BestRegion="italy" jq_filter='.regions[]' if [ -z "$BestRegion" ]; then # BestRegion not forced if [ "$pia_pf" = "true" ]; then jq_filter="${jq_filter} | select(.port_forward==true)" fi if [ "$pia_no_geo" =

Generated ELF executable segfaults during startup

别说谁变了你拦得住时间么 提交于 2020-12-12 05:10:23
问题 I'm generating an ELF executable with a .text section loaded into a LOAD segment. It disassembles fine, but trying to run it under gdb gives During startup program terminated with signal SIGSEGV, Segmentation fault. readelf gives: ELF Header: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 Class: ELF64 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: Advanced Micro Devices X86-64 Version: 0x1 Entry

Are dev_t and ino_t required to be integer types?

老子叫甜甜 提交于 2020-12-08 06:39:50
问题 The documentation for glibc stays they are integer types (no narrower than unsigned int), but I'm not finding a standards reference that says they have to be an integer type (see also time_t). So in the end, the question becomes: Is #include <stdio.h> #include <stdint.h> struct stat st; if (stat("somefile", &st) == 0) { printf("%ju %ju\n", (uintmax_t)st.st_dev, (uintmax_t)st.st_ino); } portable. 回答1: POSIX standard requires dev_t to be an integer type and ino_t to be an unsigned integer. dev