posix

Create a shell-escaped POSIX path in macOS

一世执手 提交于 2019-12-25 03:03:33
问题 I need to create a string from a full POSIX path (starting at the root), so that it could be pasted directly into a Unix shell like bash , e.g. in Terminal.app , without the need for quotes around the path. (I do not actually pass the string to a shell, but instead need it for passing it to another program. That program expects the path in just the form that you get when you drag a file into Terminal.app .) For that, I need to escape at least any spaces in the string, by prepending them with

Can Visual Stuidos be used to develop in C++ and still create a program capable of running on Mac?

和自甴很熟 提交于 2019-12-25 02:16:46
问题 For C++ development I noticed Visual Studios 2013 sort of forces the Microsoft extension onto you and I'm wondering if there's any settings that should be disabled if one is coding for maximum portability? For example when a new source file is added it comes with _tmain() which clearly isn't standard C++. In the following screen what should be selected if one wants to program for Mac, since it wouldn't be a Win32 application? I'm afraid intelitype is going to mess things up by suggesting

igraph & POSIXct

寵の児 提交于 2019-12-24 22:41:48
问题 I have the following data library(data.table); library(igraph) t <- data.table(a=seq(ISOdate(2019,1,1), ISOdate(2019,7,1), "months"), b=seq(ISOdate(2019,1,2), ISOdate(2019,7,2), "months")) g <- graph_from_edgelist(as.matrix(t[,c("a","b")])) and would like to apply subcomponent(g,ISOdate(2019,1,1),"out") but obtain the error that At structural_properties.c:1249 : subcomponent failed, Invalid vertex id Is anyone aware of a solution to this problem? Additional complication The problem is

Is there a pre-existing function or code I can use to compute a TCP segment checksum in a POSIX program

北城以北 提交于 2019-12-24 21:44:02
问题 I am writing a little POSIX program and I need to compute the checksum of a TCP segment, I would like use an existing function in order to avoid to writing one myself. Something like (pseudocode) : char *data = .... u16_integer = computeChecksum(data); I searched on the web but I did not find a right answer, any suggestion ? 回答1: Here, it's taken more or less directly from the RFC: uint16_t ip_calc_csum(int len, uint16_t * ptr) { int sum = 0; unsigned short answer = 0; unsigned short *w = ptr

Share named POSIX semaphores

别等时光非礼了梦想. 提交于 2019-12-24 20:40:11
问题 I have issues understanding how to share a POSIX semaphore among multiple processes. I am trying to do the following: 1. The producer initializes a semaphore 2. The producer posts 10 tokens to the semaphore and sleeps 1 second before doing so 3. The consumer gets a token from the semaphore When I start my producer, a segmentation fault (core dumped) occurs. Furthermore I am not sure, if my way of sharing the named semaphore is correct. Producer: #include <semaphore.h> #include <stdio.h>

Why does mmap(2) with PROT_WRITE only require a readable fd?

别来无恙 提交于 2019-12-24 15:33:46
问题 From the POSIX (IEEE Std 1003.1-2008) section on mmap : The file descriptor fildes shall have been opened with read permission, regardless of the protection options specified. Why is that? Seems like a descriptor opened O_WRONLY and mapped with PROT_WRITE and not PROT_READ shouldn't be problematic with respect to permissions, right? 回答1: But the next line states that : If PROT_WRITE is specified, the application shall ensure that it has opened the file descriptor fildes with write permission

Regex for matching literal strings

安稳与你 提交于 2019-12-24 09:58:50
问题 I'm trying to write a regular expression which will match a string. For simplicity, I'm only concerned with double quote (") strings for the moment. So far I have this: "\"[^\"]*\"" This works for most strings but fails when there is an escaped double quote such as this: "a string \" with an escaped quote" In this case, it only matches up to the escaped quote. I've tried several things to allow an escaped quote but so far I've been unsuccessful, can anyone give me a hand? 回答1: I've managed to

sem_timedwait() pthreads-win32 errno usage

廉价感情. 提交于 2019-12-24 09:24:23
问题 I am using pthreads-win32 for threads on a Win32 Application. I am calculating the timespec using the first function posted here. The call to sem_timedwait() appears to be waiting for the specified ts time, however every time it completes I get the following message: Error waiting on semaphore: No error I have checked the file of sem_timedwait.c here, and they specify the same errno values and return values. Consequently, I do not know why it is exiting with this errno, and would like to know

POSIX Timer : Signal Handler for Timer freezes

天涯浪子 提交于 2019-12-24 08:31:26
问题 This post is related to: POSIX TIMER- Have multiple timers I want to call a function in the SignalHandler. This function is a TCP socket client(getSpeed). It gets data from a server every time the timer ticks one second and sends a signal which then calls the corresponding handler. First of all I am not sure if it is good practise to call a function from a signal handler. Now the problem is, my code freezes randomly whenever I execute this program which talks to a server. If this way of

discontinuity in evaluation of midnight POSIXct objects

╄→尐↘猪︶ㄣ 提交于 2019-12-24 08:24:54
问题 I have a vector of POSIXct objects with date and time, one of which is midnight. v <- as.POSIXct(c("2019-01-01 23:59:00","2019-01-02 00:00:00"), tz="UTC") When I evaluate v , it is shown correctly, > v [1] "2019-01-01 23:59:00 UTC" "2019-01-02 00:00:00 UTC" but when I evaluate its elements separately, > v[1] [1] "2019-01-01 23:59:00 UTC" > v[2] [1] "2019-01-02 UTC" the midnight element is shortened to exclude the time, which causes trouble in my data.table join. I therefore wonder whether it