• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Calling BSD from Cocoa and/or CFM?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calling BSD from Cocoa and/or CFM?


  • Subject: Re: Calling BSD from Cocoa and/or CFM?
  • From: James Montgomerie <email@hidden>
  • Date: Mon, 21 Jan 2002 16:37:55 -0800

On Monday, January 21, 2002, at 03:52 pm, Zack Morris wrote:

> Hi, I am new to the list and have a newbie question (for future
> reference, is there a better list to ask about pure OS X questions?).

Your question is vaguely off-topic for the list (especially the CFM
part), which is really about /Cocoa/ development, though I can't
off-hand think of a better [Apple hosted] list, apart from the Carbon
one, if your app might be Carbon based.

> How
> do I call BSD UNIX routines from OS X? Specifically, I need to call
> getpwent() which is inside the pwd.h header. You can read about it by
> doing
> a "man getpwent" search in google. For some reason it didn't show up
> in man
> on my computer. I have searched my drive and cannot find the pwd.h
> file or
> getpwent in the contents. I downloaded the developer tools but that
> did not
> help. I assume that I need to download and install some unix
> libraries, but
> I don't know how. I know that the routine exists because I can call it
> from
> perl on the command line. Here is my test file called "getnames.pl":

The file should be in /usr/include. If you're looking for it in the
Finder, use Go->Go to folder... and type /usr/include in the box (/usr
is usually hidden).

> #!/usr/bin/perl
>
> setpwent();
>
> while( 1 )
> {
> @newuserpw = getpwent();
> if( @newuserpw != 0 )
> {
> printf "@newuserpw\n";
> }
> else
> {
> last;
> }
> }
>
> from the command line:
>
> perl getnames.pl

This works for me...

#include <stdio.h>
#include <pwd.h>

int main (int argc, const char * argv[]) {
struct passwd *pwd;
do {
pwd = getpwent();
if(pwd && pwd->pw_name) {
printf("User: %s\n", pwd->pw_name);
}
} while(pwd);
return 0;
}


> It then outputs a list of users on this machine. I just need a way to
> call
> it from c++, preferrably from codewarrior. Also, how do I do a lookup
> on
> the name and call it from a carbon CFM project (similar to RezLib's
> method
> of calling CF... routine for setting resolution). I am using OS X
> 10.1.2
> Build 5P48. Thank you for your time,

I'll leave the CFM questions alone... You may get a better response on
the carbon-development list :-)

Jamie.


  • Follow-Ups:
    • Re: Calling BSD from Cocoa and/or CFM?
      • From: Zack Morris <email@hidden>
    • Re: Calling BSD from Cocoa and/or CFM?
      • From: James Montgomerie <email@hidden>
References: 
 >Calling BSD from Cocoa and/or CFM? (From: Zack Morris <email@hidden>)

  • Prev by Date: Re: Calling BSD from Cocoa and/or CFM?
  • Next by Date: Re: Calling BSD from Cocoa and/or CFM?
  • Previous by thread: Re: Calling BSD from Cocoa and/or CFM?
  • Next by thread: Re: Calling BSD from Cocoa and/or CFM?
  • Index(es):
    • Date
    • Thread