Re: Equivalent of openat() on osx?
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meg.abyt.es; s=google; h=domainkey-signature:from:to:subject:date:user-agent:references :in-reply-to:reply-by:x-message:mime-version:content-type :content-transfer-encoding:message-id; bh=kh4NyjbzzNnaUQ4PSSrWFvLxxRgsu5bYeTJHXFZ2ZYI=; b=X6CKA2nM+lrkhzTPG5iHymklpIB3XWhYoLS/0DpKPnTt9gwXyoa1q6umhPHaSEquJb 5+CNZJTPmwS7Qdl3XADgGNn4oH+AC8H+VDH5oRHspW6TwwQ9Y6rXJXk45bwpzIYvV0Cb XR+wMI9UEsguaLBN7+ZvXtcEF9vOrkg0Jk6wc= Domainkey-signature: a=rsa-sha1; c=nofws; d=meg.abyt.es; s=google; h=from:to:subject:date:user-agent:references:in-reply-to:reply-by :x-message:mime-version:content-type:content-transfer-encoding :message-id; b=UuwJgCofsEWbDrMO5/QpSV1QvwsmOBjItlVkEW9LgYw6bXHqL4esaSsLbD0Bed/xP6 DBXzbNhksFfbaeHlawhqlZGkatoeDaL4iZDMJHyMxw69LHYSz4SMI9+e7IGNx6+ZB+ag Z0Ntipg20zMBtFVeWWHzC/jDUImVOiTf5682M= Reply-by: Wed, 19 Jan 2011 16:20:00 -0600 User-agent: KMail/1.13.5 (Linux/2.6.32-32-server; KDE/4.4.5; x86_64; ; ) On Thursday 05 May 2011 00:58:48 Eric Gouriou wrote:
On May 3, 2011, at 9:13 AM, Anatol Pomozov wrote:
Hi,
I am porting a Linux program to macosx (target is 10.6 version) and the program uses openat/unlinkat/... functions. Although these functions are not in POSIX, they are widely used on *nixes and the part proposal the next POSIX.
My question what is the best equivalent for the opentat() functions that can be used in multithreaded application. Currently I use something like this:
int openat(int dirfd, const char *pathname, int flags, ...) {
int fd;
if(fchdir(dirfd) < 0) {
perror("fchdir"); return -1;
}
fd = open(pathname, flags, mode); // chdir to the original CWD
return fd;
}
But this is not a perfect solution - current working directory is shared among all threads, it means that openat() may affect other threads. Is there an equivalent of this implementation without changing the current directory?
Use a per-thread CWD? Darwin supports them but I can't figure where/whether it is documented. A previous reference to this capability, from an apple.com address: <http://lists.apple.com/archives/unix-porting/2008/Mar/msg00028.html>
The *at functions are generally considered to be the way that a per-thread working directory is implemented. Perhaps the author misspoke or was referring to an as-yet unreleased version of OS X (10.7 Lion, maybe?).
However, in my opinion, the openat()/... functions are good deal more convenient than per-thread CWDs. I'm glad to hear that they are considered for inclusion in an upcoming revision of POSIX.
Based upon how it's published on the opengroup site, it appears it's already a part of POSIX.1-2008 (Base Specifications, Issue 7). -- Tilghman _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com
participants (1)
-
Tilghman Lesher