external programs
Chris Reuter
cgreuter at calum.csclub.uwaterloo.ca
Thu Jul 6 00:54:03 UTC 2000
On Wed, Jul 05, 2000 at 06:36:04PM -0300, Jecel Assumpcao Jr wrote:
> On Wed, 05 Jul 2000, Chris Reuter wrote:
> > [Yes, I realize that I'm following up to a 20 day old post. I've been
> > ignoring the list and enjoying the nice weather instead, as of late ;)]
>
> Since I have been busy with other things, this was still very timely
> and helpful.
>
> > Actually, the "system" function will do this and, since it's part of
> > the ANSI C library specification, should be available on every system
> > that runs Squeak.
>
> I have actually used this function quite a bit in my programs (mostly
> due to laziness - it is much simpler to system("rm /tmp/xxx") than to
> look up the proper functions to do this ;-)
>
The only problem is that it won't work on platforms without rm.
> Still, it took me quite a while to find that it was declared in
> stdlib.h in Linux. I had somehow managed to miss it when grepping
> /usr/include and subdirectories.
>
> My impression is that FFI is for calling functions in external
> libraries. Can it also be used for stuff like this that is in that
> standard library?
It shouldn't be an issue. Most compilers/OSs put the standard
libraries in a shared library. Of course, implementing an interface
in Squeak means determining *which* shared library/.dll contains the
ANSI lib, which varies between platforms and even between compilers on
some platforms.
So the Right Thing to do is to link them to a plugin so that the
Squeak side doesn't have to know what platform it's running on
(bare-metal ports could just use stubs).
Of course, that's not necessarily enough for "system()" because it
passes the command to a shell, which varies between platforms. The
Right Thing here would be to wrap it with a function that takes the
name, arguments, and whether or not to run the program in the
background and then calls the relevant platform-dependent function.
Fortunately, the other useful ANSI C functions (getenv() and setenv())
are straightforward.
> > There are a few other ANSI lib OS functions that would also be useful
> > to reach from Squeak such as getenv() and setenv().
>
> That would be nice.
Having just looked through Harbison&Steele, I can't see any other
OS-type functions that are in ANSI whose functionality isn't already
provided by the Squeak environment (with the possible exception of
raise() and signal()--probably more trouble than they are worth).
This would actually make a nice little learning exercise to teach
myself FFI.
--Chris
More information about the Squeak-dev
mailing list
|