Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Mac > Mac Programmer > Re: Get login n...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 49 Topic 942 of 1040
Post > Topic >>

Re: Get login name and/or path to home directory of current user?

by SM Ryan <wyrmwif@[EMAIL PROTECTED] > Jun 1, 2007 at 08:26 AM

Don Bruder <dakidd@[EMAIL PROTECTED]
> wrote:
# In article <135qa6897ko7h6c@[EMAIL PROTECTED]
>,
#  SM Ryan <wyrmwif@[EMAIL PROTECTED]
> wrote:
# 
# > # The good news is that I always know the file's path: 
# > # "/Users/LoginName/Client.log", so I can easily pass it to 
# > # FSPathMakeRef() to get an FSRef to work with.
# > 
# > char fpath[] = "%s/Client.log";
# > char path[sizeof fpath+strlen(homedirectory)];
# > sprintf(path,fpath,homedirectory);
# > 
# > FSRef is evil.
# 
# OK, I'll play along... Why is FSRef evil? Please be specific and 
# convincing. 

Because you're working on Unix now, and it's time to get into the
1970s. Unix has two simple ways to identify a file, either or both
of which are available on nearly all system calls: the file path
(char*) and the open file descriptor (int). Any complexity of 
interpretting the path are left to the kernel. FSRef is a redress
of FSSpec which was little more than an HFS directory entry. It's
a baroque interface to provide backwards compatiability with System
6 era HFS code rather than leverage new capabilities on top of
the Unix path.

It looks like Cocoa is about leveraging on the Unix kernel instead
of System 1 interfaces. (I don't use Cocoa that much yet until
Apple sup****ts garbage collection in objc.)


# Personally, I find that they're rather convenient. Much more so than 
# going through the unix gyrations you suggest. (and without needing to 
# worry about setuid and/or daemon-related "uh-oh"s, and similar weirdness

# that you mentioned later in your post.)

The other routines are other using getuid/getpwuid, or some
ProcessManager abortion. If they are using getuid, the same
considerations apply whether you are aware of it or not. So
you might as well be aware of it.

If they are using ProcessManager, that can bite you if you ever
need to write daemons. Daemon operate outside ProcessManager
and as of 10.4 Apple has a number of arbitrary barriers between
traditional Unix processes and ProcessManager processes. For example,
Applescript cannot (or at least could not into 10.4) run in daemons.
That means things like osascript can be used in Terminal, but the
identical command will (or would) fail in an Apache CGI script.

# Another poster suggested, and now that I know about it, I'll be using, 
# the Carbon function "FSFindFolder()", which gives me exactly what I'm 
# looking for (Namely, the FSRef of the user's home directory, which I can

# then graft the filename onto with an amount of heartburn that closely 
# approaches zero) in a single call. If that's "evil", mark me down as 
# part of the "brotherhood of evil coders" :) 

In Unix that's called tilde expansion which replace ~ with the home
directory of the current uid, and ~username with a specified user.
It's not done by the kernel, but there are plenty of libraries that
do it for you if you want. If you want to write programs that can be
with minimal pain to other Unices, learn the Unix way. Carbon locks
you into Apple only.

Besides doing it the Unix way means everybody writing free libraries
for Linux, BSD, and Solaris are also writing free libraries for you
on MacOSX.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
So basically, you just trace.
 




 49 Posts in Topic:
Get login name and/or path to home directory of current user?
Don Bruder <dakidd@[EM  2007-05-29 23:56:30 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-05-30 07:33:28 
Re: Get login name and/or path to home directory of current user
Don Bruder <dakidd@[EM  2007-05-30 12:39:12 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-06-01 08:26:55 
Re: Get login name and/or path to home directory of current user
Gregory Weston <uce@[E  2007-06-01 07:15:29 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-06-01 12:47:58 
Re: Get login name and/or path to home directory of current user
Gregory Weston <uce@[E  2007-06-01 10:18:03 
Re: Get login name and/or path to home directory of current user
glenn andreas <gandrea  2007-06-01 11:00:38 
Re: Get login name and/or path to home directory of current user
russotto@[EMAIL PROTECTED  2007-06-03 20:38:20 
Re: Get login name and/or path to home directory of current user
glenn andreas <gandrea  2007-06-04 08:53:09 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-06-01 18:43:50 
Re: Get login name and/or path to home directory of current user
Gregory Weston <uce@[E  2007-06-01 20:47:41 
Re: Get login name and/or path to home directory of current user
Don Bruder <dakidd@[EM  2007-06-01 19:05:34 
Re: Get login name and/or path to home directory of current user
Sean McBride <cwatson@  2007-06-02 13:26:49 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-06-04 14:08:38 
Re: Get login name and/or path to home directory of current user
Bo Lindbergh <blgl@[EM  2007-05-30 11:27:08 
Re: Get login name and/or path to home directory of current user
Don Bruder <dakidd@[EM  2007-05-30 12:41:44 
Re: Get login name and/or path to home directory of current user
David Phillip Oster <o  2007-05-31 02:51:48 
Re: Get login name and/or path to home directory of current user
Don Bruder <dakidd@[EM  2007-05-30 20:59:08 
Re: Get login name and/or path to home directory of current user
Jens Ayton <IWISNEXPQQ  2007-05-31 21:29:13 
Re: Get login name and/or path to home directory of current user
Don Bruder <dakidd@[EM  2007-05-31 23:03:31 
Re: Get login name and/or path to home directory of current user
Gregory Weston <uce@[E  2007-06-01 07:20:53 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-06-01 12:48:00 
Re: Get login name and/or path to home directory of current user
Gregory Weston <uce@[E  2007-06-01 10:28:13 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-06-01 18:43:51 
Re: Get login name and/or path to home directory of current user
Gregory Weston <uce@[E  2007-06-01 20:34:55 
Re: Get login name and/or path to home directory of current user
Don Bruder <dakidd@[EM  2007-06-01 06:07:37 
Re: Get login name and/or path to home directory of current user
Gregory Weston <uce@[E  2007-06-01 10:46:07 
Re: Get login name and/or path to home directory of current user
Michael Ash <mike@[EMA  2007-06-01 10:19:22 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-06-01 18:33:34 
Re: Get login name and/or path to home directory of current user
glenn andreas <gandrea  2007-06-01 16:14:02 
Re: Get login name and/or path to home directory of current user
Michael Ash <mike@[EMA  2007-06-01 16:54:16 
Re: Get login name and/or path to home directory of current user
Bo Lindbergh <blgl@[EM  2007-06-02 13:14:06 
Re: Get login name and/or path to home directory of current user
Michael Ash <mike@[EMA  2007-06-02 07:10:43 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-06-01 18:33:46 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-06-01 18:33:59 
Re: Get login name and/or path to home directory of current user
russotto@[EMAIL PROTECTED  2007-06-03 20:35:12 
Re: Get login name and/or path to home directory of current user
Gabriele Greco <gabrie  2007-06-11 15:59:22 
Re: Get login name and/or path to home directory of current user
Ben Artin <macdev@[EMA  2007-06-11 08:13:57 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-06-11 23:02:08 
Re: Get login name and/or path to home directory of current user
Steven Fisher <steve@[  2007-06-12 00:42:44 
Re: Get login name and/or path to home directory of current user
Gregory Weston <uce@[E  2007-06-11 20:53:38 
Re: Get login name and/or path to home directory of current user
Ben Artin <macdev@[EMA  2007-06-11 17:58:24 
Re: Get login name and/or path to home directory of current user
Gregory Weston <uce@[E  2007-06-11 17:47:12 
Re: Get login name and/or path to home directory of current user
Michael Ash <mike@[EMA  2007-06-11 19:36:11 
Re: Get login name and/or path to home directory of current user
Steven Fisher <steve@[  2007-06-12 00:41:25 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-06-01 07:52:08 
Re: Get login name and/or path to home directory of current user
Sherm Pendley <spamtra  2007-06-01 02:26:44 
Re: Get login name and/or path to home directory of current user
Clark Cox <clarkcox3@[  2007-05-31 16:24:03 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Dec 5 7:15:28 CST 2008.