Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.rmit.EDU.AU!news.unimelb.EDU.AU!munnari.OZ.AU!news.ecn.uoknor.edu!paladin.american.edu!gatech!news.mathworks.com!fu-berlin.de!news.belwue.de!news.uni-stuttgart.de!news.rhrz.uni-bonn.de!saph2.physik.uni-bonn.de!juengst
From: juengst@saph1.physik.uni-bonn.de (Henry G. Juengst)
Newsgroups: comp.unix.misc,comp.unix.bsd.misc
Subject: Re: How to delete files within C programs
Date: 1 May 1996 20:13:16 GMT
Organization: Institut fuer Strahlen- und Kernphysik
Lines: 121
Sender: juengst@saph2.physik.uni-bonn.de (Henry G. Juengst)
Distribution: world
Message-ID: <4m8gks$ibu@news.rhrz.uni-bonn.de>
References: <Oum-El-Kheir.Benkahla-3004961724540001@mac-ugm-3.imag.fr> <4m5p3k$3nq@dfw-ixnews2.ix.netcom.com> <4m7sr3$rf9@news.rhrz.uni-bonn.de> <4m8330$ebv@news.inc.net>
Reply-To: juengst@saph1.physik.uni-bonn.de
NNTP-Posting-Host: saph1.physik.uni-bonn.de
Xref: euryale.cc.adfa.oz.au comp.unix.misc:22323 comp.unix.bsd.misc:881
In article <4m8330$ebv@news.inc.net>, nelson@cs.uwp.edu (Jeremy Nelson) writes:
>Topic originally under discussion: How to remove a file under C in unix?
>
>Henry G. Juengst <juengst@saph1.physik.uni-bonn.de> wrote:
>>This might be a simple solution if you know the solution, but why should
>>a beginner know that the function to delete a file is not something like
>>'delete_file', but 'unlink' in the unix mud ?
>
>* A beginner does not attempt to program without a good tutorial and
> reference book: Such books would explain these functions reasonably;
Theoretical: yes. Obviously (not only in this case): no.
>
>Therefore:
>* A good book on ANSI C will have a reference to the function "remove",
> which is mandated by standard C.
"Remove what?" would be the first question of a beginner. You might think
it is simple, but I have teached people more than 13 years and I can tell
you that nothing is simple if it is not clear.
>* A good book on programming in C under unix would mention "unlink".
Even a reference guide would mention it. But that does not mean it is
a good book. I think a good book would emphasize that C and unix are not
the best choice for beginners.
>* The original poster said "I want to know how to do what 'rm' does in C".
> Almost without exception, if you do a 'man' on a simple system utility,
The first thing people try is 'help', not 'man'.
> there will be cross-references to related and interesting C functions. By
> checking the man pages for those functions, within a few hits, you will
Some of the 'few hits' will be to learn what this '(2)' in 'unlink(2)'
means. I hope you see that it is not so simple as you think.
> surely find what you are looking for. The man page for 'rm' is no exception.
>
>
>rm(1) User Commands rm(1)
>
>NAME
> rm, rmdir - remove files or directories
>
>SYNOPSIS
> rm [-f] [-i] filename...
>
> rm -r [-f] [-i] dirname...[filename...]
>
> rmdir [-p] [-s] dirname...
>
>[....]
>
>SEE ALSO
> rmdir(2), unlink(2), environ(5)
>
>
>Since the person wants to remove a file, i would assume they would realize
>that "rmdir" is probably not the right call: Therefore, looking at "unlink"
>and "environ" would be in order. (Of course, after looking at a few hundred
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>man pages, a programmer realizes that C function calls typically fall under
~~~~~~~~~ No more comment.
>section 2 and 3 of the man pages.)
>
>
>unlink(2) System Calls unlink(2)
>
>NAME
> unlink - remove directory entry
>
>SYNOPSIS
> #include <unistd.h>
>
> int unlink(const char *path);
>
>DESCRIPTION
> unlink() removes the directory entry named by the path name
> pointed to by path. and decrements the link count of the
> file referenced by the directory entry. When all links to a
> file have been removed and no process has the file open, the
> space occupied by the file is freed and the file ceases to
> exist.
>[....]
>
>Looks like we have a winner!
>
>
>
>>Same for 'sprintf'. This is not a function for fast sprinter. .-)
>
>All reasonably non-novice C programmers should be familiar with
>the presence and use of the sprintf() function. If they are not, its time
>to go back and refer to your C tutorial book. I dont think its unreasonable
>for someone to expect another C programmer to know about sprintf(). (IMO)
Are you sure? Have you seen the "solution" using the function of the
exec family? What makes you sure that most people know a C programmer
with enough experiences?
>
>The information is all there: You just have to learn how to go find it.
This is a banality, but it is not always helpful.
>
>Jeremy Nelson
Henry
--
juengst@saph1.physik.uni-bonn.de [131.220.161.1] (Internet)
omni:.de.uni-bonn.physik.saph1::juengst (DECnet/OSI, phase V)
saph1::juengst [26.358] (DECnet, phase IV)
Any opinions in this mail are my own.