USER command questions (Fairlight)

Fairlight fairlite at fairlite.com
Fri Sep 11 11:25:07 PDT 2009


Four score and seven years--eh, screw that!
At about Fri, Sep 11, 2009 at 07:46:21AM -0700,
Tyler blabbed on about:
> Thanks Mark!  That was exactly the answer I was looking for!  I will stick
> with SYSTEM for mv then, and OPENDIR/NEXTDIR for getting the filenames :)
> (thanks to John Esak for the demo on how OPENDIR's usage)

Saw your other posts regarding why you wanted to avoid SYSTEM.  In essence,
it simply generates one extra shell process per SYSTEM invocation.  Same as
any C process using the system(2) function...

If you're really worried about the overhead and wish to avoid it, write a
little routine with OPEN/READ/WRITE/CLOSE to copy files, and add a REMOVE
on the origin file if you want it to effectively be a move.  This won't
preserve file timestamps as `mv` would, btw, since it's really a full copy
and unlink, rather than altering the inode.  That's the one caveat.

The routines you need to write for this are really very short, too:

::IHandle=open(UpReal,"rb"):
:IHandle lt "0":ErrMsg="Could not open upload file.";call "upform";exit:
::OHandle=open(UpDest,"wc0b"):
:OHandle lt "0":ErrMsg="Could not open storage file.";call "upform";exit:
::FPos="0":
cploop::ln=read(IHandle,FLine,"8192"):
:FPos lt UpSize and ln eq "0":ErrMsg="Premature end of file during copy.";call "upform";exit:
::lo=write(OHandle,FLine):
:lo ne ln:ErrMsg="Could not write entire line to file during copy.";call "upform";exit:
:FPos lt UpSize:FPos=FPos+ln;goto cploop:
::ln=close(IHandle);ln=close(OHandle):

FLine is just a declared but uncast variable.  IHandle and OHandle are
defined (4,.0), and ln is just an uncast dummy.

Obviously, you'd replace the fault tolerance sections.  I ripped this out
of a web-based file upload procedure where it takes the files and copies
them to safe locations entirely platform agnostically.

And as I said, if you need to "move", just add a REMOVE in there after the
last line.

mark->
-- 
Audio panton, cogito singularis,


More information about the Filepro-list mailing list