Jump to content
  • Advertisement
Sign in to follow this  
Raduprv

Deleting a file in C

This topic is 4871 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Umm, this is kind of embarasing, but so far, in my 3 years of C I never needed to delete a file. I think that the function is unlink() but I am not 100% sure (from what I read, it does some fancy things, such as decrementing the refference count and such). So, is unlink() the [only/right] way to delete a file? P.S. I need a generic C function, not windows or something.

Share this post


Link to post
Share on other sites
Advertisement
unlink is a POSIX function that generally isn't available on Windows (although VC++ does emulate it). I don't know if there is a general delete file function.

Share this post


Link to post
Share on other sites
Well, DevC++ (gcc) seems to know about it.
This is for an MMORPG server and it will run on Posix (FreeBSD), and on Windows for local testing.
If VC can also emulate it, the better (one developer has VC).

Share this post


Link to post
Share on other sites
Googled and found this:
remove

Quote:

int remove ( const char * filename );

Delete a file.
Deletes the file specified by filename. It is compiled as a call to the system function for deleting files (unlink, erase or del).

Parameters.

filename
Path and name of the file to be removed.

Return Value.
If the file is succesfully deleted a 0 value is returned.
On error a non-zero value is returned and the errno variable is set with the corresponding error code that that can be printed with a call to perror:

Share this post


Link to post
Share on other sites
remove() is not standard. unlink() is the POSIX standard -- the talk about "reference counts" is what "delete a file" really means on UNIX systems. Usually, it just removes the file (unless there are multiple hard links).

Share this post


Link to post
Share on other sites
Quote:
Original post by hplus0603
remove() is not standard. unlink() is the POSIX standard -- the talk about "reference counts" is what "delete a file" really means on UNIX systems. Usually, it just removes the file (unless there are multiple hard links).


Now where'd you learn that? I have multiple sources that say remove is standard:

Quote:
From subpages of http://www.unix.org/version3/apis.html, previously linked in this thread:

			POSIX			P96
Interface XSI Base U98 U95 P92 C99 C89 SVID3 BSD
[...]
remove() m m m m m m m m .
[...]
unlink() m m m m m . . m m
[...]
m Indicates that the interface is defined as mandatory.
[...]
. Indicates that the interface is not specified.


Quote:
From panda@industry:~$ man 3 remove:
NAME
remove - delete a name and possibly the file it refers to

SYNOPSIS
#include <stdio.h>

int remove(const char *pathname);
[...]

CONFORMING TO
ANSI C, SVID, AT&T, POSIX, X/OPEN, BSD 4.3

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
This book on ANSI C by Kernighan and Ritchie and Bell Labs (who wrote the language, I believe), has remove() as a standard library function.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!