From: Krzysztof Drewniak on
pjb(a)informatimago.com (Pascal J. Bourguignon) writes:

> Krzysztof Drewniak <krzysdrewniakNOSPAM(a)gmai.com> writes:
>
>> pjb(a)informatimago.com (Pascal J. Bourguignon) writes:
>>
>>> Zach Beane <xach(a)xach.com> writes:
>>>
>>>> Krzysztof Drewniak <krzysdrewniakNOSPAM(a)gmai.com> writes:
>>>>
>>>>> I am trying to develop a roguelike game in lisp. This game has a
>>>>> platform+implementation bit to select the name of the player. On *nix,
>>>>> it just rips your login id. On clisp, there is a small
>>>>> problem. Somewhere between 2.44 and 2.48 the function (posix:getuid) was
>>>>> renames to (posix:uid) . The application will be fired up with both old
>>>>> and new versions of clisp and I need a workaround to work with both and
>>>>> not trigger the "Package POSIX has no external symbol GETUID/UID" which
>>>>> is what happens if I try (if (bpoudp '...) ... other...)
>>>>
>>>> One possibility:
>>>>
>>>> (funcall (or (find-symbol "UID" "POSIX")
>>>> (find-symbol "GETUID" "POSIX")
>>>> (error "Couldn't find POSIX:UID or POSIX:GETUID")))
>>>>
>>>> Zach
>>>
>>> (funcall (or (ignore-errors (find-symbol "UID" "POSIX"))
>>> (ignore-errors (find-symbol "GETUID" "POSIX"))
>>> (error "Couldn't find POSIX:UID or POSIX:GETUID")))
>>>
>>> or:
>>>
>>> (funcall (if (find-package "POSIX")
>>> (or (find-symbol "UID" "POSIX")
>>> (find-symbol "GETUID" "POSIX")
>>> (error "Couldn't find POSIX:UID or POSIX:GETUID"))
>>> (error "Couldn't even find the POSIX package")))
>> Zach's solution worked.
>
> Yes. Until you find a clisp without a POSIX package, and you come
> back here asking how to deal with versions of clisp without a POSIX
> package...
>
> Notice also that FFI and LINUX are not always present.
>
Also, the entire function in which this is buried is preceded by #+unix
and the statement has a #+clisp attached to it. Non-UNIX platforms get
user input on the question of who they are (also, this is a function
that gets a user name (for which a standard method chain on non-POSIX
*escapes* me))

>> This is also one of the more helpful groups on USENET.

--
X-Real-Email-With-Antispam: krzysdrewniak at gmail dot com
pgp key on keyserver.ubuntu.com and maybe some other place too
From: D Herring on
On 06/25/2010 07:25 PM, Krzysztof Drewniak wrote:
> pjb(a)informatimago.com (Pascal J. Bourguignon) writes:
>> Notice also that FFI and LINUX are not always present.
>>
> Also, the entire function in which this is buried is preceded by #+unix
> and the statement has a #+clisp attached to it. Non-UNIX platforms get
> user input on the question of who they are (also, this is a function
> that gets a user name (for which a standard method chain on non-POSIX
> *escapes* me))

Here's a trick to get the username on many systems.
(car (last (pathname-directory (user-homedir-pathname))))

You might also look for a $USER environment variable (may be different
name on MSWin).

- Daniel
From: Pascal J. Bourguignon on
D Herring <dherring(a)at.tentpost.dot.com> writes:

> On 06/25/2010 07:25 PM, Krzysztof Drewniak wrote:
>> pjb(a)informatimago.com (Pascal J. Bourguignon) writes:
>>> Notice also that FFI and LINUX are not always present.
>>>
>> Also, the entire function in which this is buried is preceded by #+unix
>> and the statement has a #+clisp attached to it. Non-UNIX platforms get
>> user input on the question of who they are (also, this is a function
>> that gets a user name (for which a standard method chain on non-POSIX
>> *escapes* me))
>
> Here's a trick to get the username on many systems.
> (car (last (pathname-directory (user-homedir-pathname))))

This is a big assumption. Nothing impose such a constraint on unix
systems.

On some unix systems, you may use COM.INFORMATIMAGO.COMMON-LISP.PASSWD
to read /etc/passwd and find the name of the user whose homedir is such.

But on modern unix systems, the passwd database is often kept in other
repositories, such as ldap or stranger proprietary databases
(cf. NeXTstep or Apple).

In any case, the point is that the name of the homedir is not
necessarily the login name, and is not the name of the user.


> You might also look for a $USER environment variable (may be different
> name on MSWin).

Could be better, but it's not always set either.



What about asking the user his name?

--
__Pascal Bourguignon__ http://www.informatimago.com/
From: Rob Warnock on
D Herring <dherring(a)at.tentpost.dot.com> wrote:
+---------------
| Here's a trick to get the username on many systems.
| (car (last (pathname-directory (user-homedir-pathname))))
+---------------

Hmmm...

cmucl> (car (last (pathname-directory (user-homedir-pathname))))

#<SEARCH-LIST home>
cmucl>

+---------------
| You might also look for a $USER environment variable (may be different
| name on MSWin).
+---------------

Now we have to ask what the GETENV function is called and in which
package *it* resides, e.g.:

http://cl-cookbook.sourceforge.net/os.html
...
Accessing Environment variables


-Rob

-----
Rob Warnock <rpw3(a)rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607


From: D Herring on
On 06/25/2010 10:37 PM, Rob Warnock wrote:
> D Herring<dherring(a)at.tentpost.dot.com> wrote:
> +---------------
> | Here's a trick to get the username on many systems.
> | (car (last (pathname-directory (user-homedir-pathname))))
> +---------------
>
> Hmmm...
>
> cmucl> (car (last (pathname-directory (user-homedir-pathname))))
>
> #<SEARCH-LIST home>
> cmucl>

Ahh yes, CMUCL needs a truename in there.
(car (last (pathname-directory (truename (user-homedir-pathname)))))

- Daniel