posix

POSIXct times around DST?

I want to subtract 1 day from a POSIX date and end up at the same time around DST. For example, when I add a day: > as.POSIXct('2009-03-08 23:00:00.000') + 86400 [1] "2009-03-09 23:00:00 EDT" But when I go past, it offsets: > as.POSIXct('2009-03-08 23:00:00.000') - 86400 [1] "2009-03-07 22:00:00 EST" What's the best way to deal ...

Is there a Unicode equivalent for `{\pGraph}` in Java / POSIX regular expressions?

According to the documentation of java.util.Pattern, the POSIX character class \p{Graph} ([:graph:] in POSIX notation) matches "a visible character: [\p{Alnum}\p{Punct}]". However, this is limited to ASCII characters only. Is there an equivalent class or expression for matching (visible) Unicode characters? ...

Mystery pthread problem with fork()

I have a program which: has a main thread (1) which starts a server thread (2) and another (4). the server thread (2) does an accept(), then creates a new thread (3) to handle the connection. At some point, thread (4) does a fork/exec to run another program which should connect to the socket that thread (2) is listening to. Occasion...

Get year from boost ptime

Hi, This is my first post on stackoverflow. First of all I'd like to say thanks for this site! It has provided many excellent answers to questions I've had in the past few months. I'm still learning C++, coming from vb6. I'm converting an existing program to C++ and here need to manipulate Sybase timestamps. These timestamps contain dat...

expected behavior of posix extended regex: (()|abc)xyz

On my OS X 10.5.8 machine, using the regcomp and regexec C functions to match the extended regex "(()|abc)xyz", I find a match for the string "abcxyz" but only from offset 3 to offset 6. My expectation was that the entire string would be matched and that I would see a submatch for the initial "abc" part of the string. When I try the sa...

SSL_accept hangs after calling fork()

Hi I'm writing an app in C++ using openssl, and I can't seem to get the ssl socket connection to work. I have an abstract class, with multiple functions implemented using various protocols by the inheriting classes and simple TCP and UDP ( posix sockets ) work fine. I could not get the ssl working though and after some code browsing ...

What is better for a message queue? mutex & cond or mutex&semaphore?

I am implementing a C++ message queue based on a std::queue. As I need popers to wait on an empty queue I was considering using mutex for mutual exclusion and cond for suspending threads on empty queue, as glib does with the gasyncqueue. However it looks to me that a mutex&semaphore would do the job, I think it contains an integer and ...

Portable way to achieve ls' -v flag (i.e. sort by version)?

I'm working on a some build scripts that I'd like to depend on only standardized features. I need to sort some files by version. Say the files are bar-1.{0,2,3} bar-11.{0,2,3}. By default, ls gives me: bar-1_0 bar-11_0 bar-11_2 bar-11_3 bar-1_2 bar-1_3 Getting what I want is easy using 'ls -v': bar-1_0 bar-1_2 bar-1_3 bar-11_0 bar-...

Do threads clean-up after themselves in Win32/MFC and POSIX?

I am working on a multithreaded program using C++ and Boost. I am using a helper thread to eagerly initialize a resource asynchronously. If I detach the thread and all references to the thread go out of scope, have I leaked any resources? Or does the thread clean-up after itself (i.e. it's stack and any other system resources needed for ...

Perl: Blocking signal NOT delayed as it should be -> Test code provided.

In a Perl script I'm writing I'm having a problem where I block the INT and QUIT signals, execute a process within backticks, and then unblock the INT and QUIT signals. I want to prevent an INT or a QUIT from reaching the child process and killing it. The script successfully blocks and unblocks at the right points in the code, however...

shell matching a pattern using a case-statement which is stored inside a variable

I am trying to match a pattern with a case-statement where the pattern is stored inside a variable. Here is a minimal example: PATTERN="foo|bar|baz|bla" case "foo" in ${PATTERN}) printf "matched\n" ;; *) printf "no match\n" ;; esac Unfortunately the "|" seems to be escaped (interestingly "*" or...

Example of realpath function (C Programming)

I'm looking for an example of how to use the realpath function in a C program. I can't seem to find one on the web or in any of my C programming books. ...

POSIX Threads: are pthreads_cond_wait() and others systemcalls?

The POSIX standard defines several routines for thread synchronization, based on concepts like mutexes and conditional variables. my question is now: are these (like e.g. pthreads_cond_init(), pthreads_mutex_init(), pthreads_mutex_lock()... and so on) system calls or just library calls? i know they are included via "pthread.h", but do t...

Why writing writing to unconnected socket sends SIGPIPE first?

There are so many possible errors in POSIX environement. Why some of them (write to unconnected socket in particular) get special treatment in form of signals? ...

How to handle execvp(...) errors after fork()?

I do the regular thing: fork() execvp(cmd, ) in child If execvp fails because no cmd is found, how can I notice this error in parent process? ...

How to wait for process child?

I do the usual fork + exec combination: int sockets [2]; socketpair (AF_LOCAL, SOCK_STREAM, 0, sockets); int pid = fork (); if (pid == 0) { // child dup2 (sockets[0], STDIN_FILENO); dup2 (sockets[0], STDOUT_FILENO); execvp (argv[0], argv); _exit (123); } // parent close (sockets[0]); // TODO wait and see if child crashes I...

Good collection of libraries for C?

I'm looking for a good collection of libraries for ANSI-C, stuff for handling vectors, hash maps, binary tress, string processing, etc. ...

Can I use POSIX threads in iPhone OS?

Are these available for iPhone OS? The Threading Programming Guide mentions these but does not say if they are also relevant on iPhone OS. ...

Is it possible to create a real nondetached (joinable) thread in iPhone OS?

I wonder what would happen when I create a joinable thread for writing some big data to "disk". Now, the docs say I can do so by using POSIX threads. Nice! But: Another guy at Apple said, that an app has like 5 seconds or so to quit when the user presses the home button. So for my understanding a "real" nondetached thread has the sense t...

Is there a standard way to convert a struct timeval into a struct timespec?

struct timeval represents and instant in time with two members, tv_sec (seconds) and tv_usec (microseconds). In this representation, tv_usec is not by itself an absolute time it is a sub second offset off of tv_sec. struct timespec works the same way except that instead of microseconds it's offset (tv_nsec) is stored in nanosecond units...