Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C Across Unix Platforms

Status
Not open for further replies.

OhNoNotAgain

Programmer
May 21, 2003
6
0
0
AU
Hello All,

I have to write a C program that will work on AIX, HP-UX, Solaris and Linux boxes. The program will simply list files in a given directory that start with the word install_ and will display the found files in a menu for the user to select.

So far I have only done some testing on HP-UX, to get the list of files in the dir I am using opendir and readdir.

Q1. What calls would you recommend that will work across platforms to do the same as opendir, readdir or are these two OK.

Q2. This also needs to work across machines. For eg box1 has a mount point /mnt that points to box2:/usr/local/scriptdir, my program will be run on box1 doing a search for files starting with install_ in /mnt

Any advice or useful webpages would be very welcome. I can program but am new to C.

Thanks.
 
Do an experiment - write some test code (nothing fancy) which prints all the files in the current directory only, and try it on all the machines.

> Q1. What calls would you recommend that will work across platforms to do the same as opendir, readdir or are these two OK.
You're probably OK with those two (and closedir())
Read the manual page for each one, and look for lines like this...
Code:
CONFORMING TO
       SVID 3, POSIX, BSD 4.3, ISO 9899
ISO9899 is standard C, so you should be fine with that wherever you go.

The next best thing to look out for is POSIX. POSIX defines a core set of operating system services which should be available on all the operating systems you've listed.

If its either SVID or BSD, then you're starting to restrict yourself to some subset of unix variants.

The less widely available a function is, the more you will want to isolate its use in your code, so as to minimise the amount of effort when you have to go with 'plan B', and work around its absense.

> Q2. This also needs to work across machines...
I don't think the mount points come into it that much - it all looks like part of the regular file system.
However, you probably want to specify where to start searching from on the command line, like
Code:
installmenuprog /home/files
installmenuprog /packages/install
 
Best do your testing on Sun first. Both HPUX and AIX allow null pointer indirection. i.e. the following will not break the code
Code:
int* x = 0;
*x = 5;
If you have one of those in your program, it falls flat on its face when you run it on Sun.

Also, don't forget the closedir.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top