Re: File move programatically in C



On June 15, 2009 12:08, in comp.os.linux.development.apps, Rainer Weikusat
(rweikusat@xxxxxxxxxxx) wrote:

Lew Pitcher <lpitcher@xxxxxxxxxxxx> writes:
On June 15, 2009 04:23, in comp.os.linux.development.apps, Roy Strachan
(rd@xxxxxx) wrote:

I'm trying to write a program to reorganize files on an Ubuntu Linux
8.04 box. I have it mostly working but I can't find a function to
move files. Since mv is a common function in both GUI and CLI there
is probably a function to do this. Does anyone know what that
function (or functions) is? It could probably be done with a call to
the system, but you don't learn anything that way. Any help or
pointers on where to look appreciated.

High-level abstraction: rename(2)/renameat(2) ("man 2 rename")
Low-level abstraction(s): link(2)/linkat(2), symlink(2)/symlinkat(2),
unlink(2), open(2)/creat(2), read(2), write(2),
close(2)

rename(2) is a system call which changes the name pointing to a
particular file with the limitation that it doesn't work accross file
system boundaries.

Given that Unixish systems /started with/ link(2) and unlink(2), and did not
have a rename(2), the rename(2) syscall abstracts the syscall pattern of
{if (link(oldpath, newpath)) unlink(oldpath);} into a single syscall. Thus,
to me, rename(2) is a higher-level abstraction than link(2) and unlink(2).


It is not some type of 'abstraction' build onto what you refer to
as 'lower level' above.

See my comment above.

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------


.