Re: changing player names

From: Daniel A. Koepke (
Date: 08/24/01

On Fri, 24 Aug 2001, Kras Kresh wrote:

> I've recently added a change name function, but i'm relying on system() to
> move the crash files and such to the new name. Is there a cleaner way to do
> this? I had to use bufs all over the function just to store the "mv name1
> name2" so that system() can use it.

rename() is part of the C standard library and is declared in stdio.h.  An
example of its use:

  rename("old", "new");

There is rarely a need to call system() to do things this fundamental.
In fact, there is very rarely a need to call system() at all.  Other
simple routines that do things people often are tempted to use system()

  link(2)       Create a hard link.
  unlink(2)     Delete a link and possibly the file (see below).
  symlink(2)    Create a symbolic link.
  rmdir(2)      Remove a directory, if it's empty.
  remove(3)     Calls unlink() on files, rmdir() on directories.
  stat(2)       Gather information on a file.

The unlink(2) system call is so named because it removes a name from a
file.  A file may have several names in addition to the one that was
originally applied.  These other names are called "hard links" and differ
from symbolic links in that they refer to the actual file (that is, where
it's stored on disk) rather than to the filename (that is, where it's
stored in the directory structure).  If you call unlink(2) on a file and
it has no other names (hard links to it) than the one you're unlinking,
the file will be deleted.  The deletion may be delayed while there are
open file descriptors for that given file.  When all of the open
references to the file are closed, the file will be removed.  This is
basically the same idea as reference counting: as long as there are names
referring to the actual physical file data, the file exists; when those
names reach zero, the file is garbage collected.  Symbolic links don't
refer to the file, but to a filename, so they don't count as a reference.

That's a bit more of a UNIX primer than I would have liked to give, but a
lot of people are confused by this concept.  It's better to clear up any
potential confusion now than deal with it later.


   | FAQ: |
   | Archives: |

This archive was generated by hypermail 2b30 : 12/06/01 PST