如何在不使用C程序中的remove系统调用的情况下删除文件? [英] How to delete a file without using remove system call in a C program?

查看:244
本文介绍了如何在不使用C程序中的remove系统调用的情况下删除文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇Linux中rem的工作方式,并试图编写自己的C代码以删除文件,但是当我搜索答案时,我只得到了正在使用remove()系统的程序打电话.

I've been curious how rem in Linux works and trying to write my own C code that can delete a file but when I searched for the answer, I only got the programs that were using remove() system call.

还有其他方法可以不使用系统调用,例如编写自己的代码来完成这项工作吗?

Is there any other way of doing it without using system call like writing your own code to do the job?

我已经完成了通过C归档复制文件的操作,但是找不到通过C删除文件的解决方案.

I've accomplished copying file through C filing but can't find a solution to delete a file through C.

推荐答案

如果要删除文件,请使用

If you want to delete a file use the

remove

功能.如果您想看一看标准库的幕后故事,可以下载glibc的源代码(例如)并看一下实现.您将看到实际上INTERNAL_SYSCALL将在linux os上执行:

function. If you want to have a look behind the scenes of the standard library, you may download the source of the glibc (e.g.) and have a look at the implementation. You will see that actually a INTERNAL_SYSCALL will be performed on linux os:

result = INTERNAL_SYSCALL (unlink, err, 1, file);

(来自debian eglibc-2.15软件包中的/sysdeps/unix/sysv/linux/unlinkat.c)

(from /sysdeps/unix/sysv/linux/unlinkat.c from the debian eglibc-2.15 package)

如果您想进一步使用甚至不使用该系统调用,则必须实现自己的文件系统逻辑,因为文件系统syscall只是为不同的文件系统提供了一个抽象层.

If you want to go further and even not use that syscall you will have to implement your own file system logic since the file system syscall just gives an abstraction layer to different filesystems.

这篇关于如何在不使用C程序中的remove系统调用的情况下删除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆