In article <q28Di.48239$ XXXX@XXXXX.COM >,
% I'm porting some programs from OS/2 to Linux.
% Is there an easy way to tell how much free space remains on a flash drive
% or SD card etc?
% On OS/2 I use SysDriveInfo but on Linux I've had to resort to parsing the output
% of DF or VDIR.
There are some portability issues surrounding this functionality, but
my version of rexxutil does support sysdriveinfo on unix systems, altough
the default Linux Makefile doesn't compile it in...
Here's a function which returns the amount of free space on the file
system containing the file named in its argument. It works at least on
fedora core 5.
Save it to a file (call it freespace.c) and compile it with
cc -I /usr/local/include -fpic -shared freespace.c -o libfreespace.so
(replacing /usr/local/include with the directory containing rexxsaa.h).
Then copy libfreespace.so to wherever your rexx .so files are.
You can then use it with
call rxfuncadd 'freespace', 'freespace', 'freespace'
Note, for object rexx you might not need the 'lib' prefix on the .so file.
/* c file begins */
APIRET APIENTRY freespace(PUCHAR fname, ULONG argc, PRXSTRING argv,
PSZ pSomething, PRXSTRING result)
struct statfs sfs;
long long freespace;
char * dname;
if (argc != 1)
dname = alloca(RXSTRLEN(argv)+1);
memcpy(dname, RXSTRPTR(argv), RXSTRLEN(argv));
dname[RXSTRLEN(argv)] = 0;
if (statfs(dname, &sfs) == -1)
result->strlength = 0;
freespace = sfs.f_bavail;
freespace *= sfs.f_bsize;
result->strlength = sprintf(RXSTRPTR(result), "%lld", freespace);
/* c file ends */
Patrick TJ McPhee
North York Canada