From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id A0412BC6B for ; Thu, 12 Apr 2007 14:06:26 +0200 (CEST) Received: from stag.seas.upenn.edu (stag.seas.upenn.edu [158.130.70.79]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l3CC6P28003742 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 12 Apr 2007 14:06:26 +0200 Received: from [192.168.1.103] (dsl092-055-223.phl1.dsl.speakeasy.net [66.92.55.223]) (authenticated bits=0) by stag.seas.upenn.edu (8.13.6/8.13.6) with ESMTP id l3CC6Fo6013681 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Thu, 12 Apr 2007 08:06:15 -0400 In-Reply-To: <20070412085007.GA9614@pulp.rsise.anu.edu.au> References: <20070412085007.GA9614@pulp.rsise.anu.edu.au> Mime-Version: 1.0 (Apple Message framework v752.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Cc: ocaml ml Content-Transfer-Encoding: 7bit From: "Brian E. Aydemir" Subject: Re: [Caml-list] getlogin : no such file or directory ?? Date: Thu, 12 Apr 2007 08:06:09 -0400 To: Pietro Abate X-Mailer: Apple Mail (2.752.2) X-Miltered: at discorde with ID 461E20C1.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; failwith:01 ocaml:01 cheers:01 2007,:98 unix:01 unix:01 wrote:01 macosx:01 upenn:01 exception:01 caml-list:01 python:02 string:02 seems:03 let:03 On Apr 12, 2007, at 4:50 AM, Pietro Abate wrote: > why the Unix.getlogin function returns "no such file or directory" > if the unix getlogin() function returns null (see getlogin.c) ? > > ex: > ----------- > let main () = > try > print_string (Unix.getlogin()) > with Unix.Unix_error(e,_,_) -> > failwith (Unix.error_message e) > ;; > > main () > --------- > > echo "a" | ./a.out > Fatal error: exception Failure(No such file or directory") > > How can I use getlogin if I want to pass something on the standard > input > to my program ? > > The same example works with MacOsX. Why this difference ? It looks like OCaml simply calls the operating system's implementation of getlogin(). I ran into a similar issue with Python code a while back, so that's where my experience with this comes from. The problem is that it seems not all Unix-like operating systems implement getlogin() in exactly the same way. For example, getlogin () under Linux dies with the "No such file or directory" error when standard-in is not a terminal. getlogin() under Mac OS X doesn't seem to care what standard-in is. The man pages for getlogin might say something about this, as well. My solution was to use getpwuid(getuid()) instead of getlogin(). Cheers, Brian