posix

Are POSIX' read() and write() system calls atomic?

这一生的挚爱 提交于 2019-12-17 20:15:40
问题 I am trying to implement a database index based on the data structure (B link tree) and algorithms suggested by Lehman and Yao in this paper. In page 2, the authors state that: The disk is partitioned in sections of fixed size (physical pages; in this paper, these correspond to the nodes of the tree). These are the only units that can be read or written by a process. [emphasis mine] (...) (...) a process is allowed to lock and unlock a disk page. This lock gives that process exclusive

Is a semicolon prohibited after NAME in `for NAME do …`?

﹥>﹥吖頭↗ 提交于 2019-12-17 19:24:26
问题 The bash manual lists the syntax for the for compound statement as for name [ [ in [ word ... ] ] ; ] do list ; done which implies that the semicolon before do is optional if the in clause is omitted. [Note 2]. However, the Posix specification lists only the following three productions for for_clause : for_clause : For name linebreak do_group | For name linebreak in sequential_sep do_group | For name linebreak in wordlist sequential_sep do_group ; For reference, linebreak is a possibly-empty

Is it always safe to convert an integer value to void* and back again in POSIX?

穿精又带淫゛_ 提交于 2019-12-17 19:17:40
问题 This question is almost a duplicate of some others I've found, but this specifically concerns POSIX, and a very common example in pthreads that I've encountered several times. I'm mostly concerned with the current state of affairs (i.e., C99 and POSIX.1-2008 or later), but any interesting historical information is of course interesting as well. The question basically boils down to whether b will always take the same value as a in the following code: long int a = /* some valid value */ void

Speedup conversion of 2 million rows of date strings to POSIX.ct

佐手、 提交于 2019-12-17 18:53:22
问题 I have a csv which includes about 2 million rows of date strings in the format: 2012/11/13 21:10:00 Lets call that csv$Date.and.Time I want to convert these dates (and their accompanying data) to xts as fast as possible I have written a script which performs the conversion just fine (see below), but it's terribly slow and I'd like to speed this up as much as possible. Here is my current methodology. Does anyone have any suggestions on how to make this faster? dt <- as.POSIXct(csv$Date.and

What is the difference between ssize_t and ptrdiff_t?

我的梦境 提交于 2019-12-17 18:51:06
问题 The C standard (ISO/IEC 9899:2011 or 9899:1999) defines a type ptrdiff_t in <stddef.h> . The POSIX standard (ISO/IEC 9945; IEEE Std 1003.1-2008) defines a type ssize_t in <sys/types.h> . What is the difference between these types (or why were both deemed necessary)? Is there an implementation where the underlying base type for ssize_t is not the same as for ptrdiff_t ? 回答1: Is there an implementation where the underlying base type for ssize_t is not the same as for ptrdiff_t? x86-16 with the

Find out if a command exists on POSIX system

梦想的初衷 提交于 2019-12-17 18:37:06
问题 I want to be able to tell if a command exists on any POSIX system from a shell script. On Linux, I can do the following: if which <command>; then ...snip... fi However, Solaris and MacOS which do not give an exit failure code when the command does not exist, they just print an error message to STDOUT. Also, I recently discovered that the which command itself is not POSIX (see http://pubs.opengroup.org/onlinepubs/9699919799/idx/utilities.html) Any ideas? 回答1: command -v is a POSIX specified

How to be notified of file/directory change in C/C++, ideally using POSIX

流过昼夜 提交于 2019-12-17 17:44:28
问题 The subject says it all - normally easy and cross platform way is to poll, intelligently. But every OS has some means to notify without polling. Is it possible in a reasonably cross platform way? (I only really care about Windows and Linux, but I use mac, so I thought posix may help?) 回答1: Linux users can use inotify inotify is a Linux kernel subsystem that provides file system event notification. Some goodies for Windows fellows: File Change Notification on MSDN "When Folders Change" article

Naming scheme for typedefs

冷暖自知 提交于 2019-12-17 16:30:52
问题 I'm working on a library that extensively used constructs like typedef struct foo_bar_s { ... } foo_bar_t; It's a bad idea to use the _t suffix, because it's a POSIX reserved namespace. The _s suffix for structs is also pretty useless. So I thought I can change it all to typedef struct foo_bar { ... } foo_bar; or if the struct name is not needed typedef struct { ... } foo_bar; However, I cannot distinguish typedefs from regular symbols (variables, etc.) anymore. Is this really such a big deal

How to convert from UTC to local time in C?

与世无争的帅哥 提交于 2019-12-17 16:13:28
问题 It's a simple question, but the solution appears to be far from simple. I would like to know how to convert from UTC to local time. I am looking for a solution in C that's standard and more or less guaranteed to work on any computer at any location. I have read the following links carefully but I can't find a solution there: Converting string containing localtime into UTC in C Converting Between Local Times and GMT/UTC in C/C++ I have tried a number of variations, such as (datetime is a

Reference a GNU C (POSIX) DLL built in GCC against Cygwin, from C#/NET

别来无恙 提交于 2019-12-17 16:09:41
问题 Here is what I want: I have a huge legacy C/C++ codebase written for POSIX, including some very POSIX specific stuff like pthreads. This can be compiled on Cygwin/GCC and run as an executable under Windows with the Cygwin DLL. What I would like to do is build the codebase itself into a Windows DLL that I can then reference from C# and write a wrapper around it to access some parts of it programatically. I have tried this approach with the very simple "hello world" example at http://www.cygwin