*BSD News Article 67853


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.mira.net.au!inquo!in-news.erinet.com!izzy.net!aanews.merit.net!newsxfer.itd.umich.edu!newsxfer2.itd.umich.edu!newsfeed.internetmci.com!in1.uu.net!dziuxsolim.rutgers.edu!toolbox.rutgers.edu!not-for-mail
From: rgaine@toolbox.rutgers.edu (Richard C. Gaine III)
Newsgroups: comp.unix.misc,comp.unix.bsd.misc
Subject: Re: How to delete files within C programs
Date: 6 May 1996 18:15:31 -0400
Organization: Rutgers University
Lines: 34
Message-ID: <4mltm3$90u@toolbox.rutgers.edu>
References: <Oum-El-Kheir.Benkahla-3004961724540001@mac-ugm-3.imag.fr> <318AAE1A.636C@david.silesia.pik-net.pl>
NNTP-Posting-Host: toolbox.rutgers.edu
Xref: euryale.cc.adfa.oz.au comp.unix.misc:22469 comp.unix.bsd.misc:927

Wojtek Cieplak <wojtekc@david.silesia.pik-net.pl> writes:

>Oum-El-Kheir Benkahla wrote:
>> 
>>    I am searching a way for deleting files within C programs. I tried the
>> exec command for executing rm (execlp("rm", "rm", "myfile", 0),

>You can try use unlink library function.
>Unlink function work always correct.

>Wojtek
main() {
	remove("/path/to/myfile");
}
NAME
     remove - remove file

SYNOPSIS
     #include <stdio.h>

     int remove(const char *path);

MT-LEVEL
     MT-Safe

DESCRIPTION
     remove() causes the file or empty directory  whose  name  is
     the  string pointed to by path to be no longer accessible by
     that name.  A subsequent attempt to  open  that  file  using
     that name will fail, unless the file is created anew.

     For files, remove() is identical to  unlink().   For  direc-
     tories, remove() is identical to rmdir().