0
我需要刪除給定的路徑使用unlinkat()
目錄,程序運行良好,但它不會刪除(取消鏈接)該目錄(順便說一句)。使用man7文檔unlinkat()
我有以下代碼:unlinkat()在C目錄
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pwd.h>
#include <grp.h>
#include <dirent.h>
#include <fcntl.h>
void main(int argc,char *argv[]){
DIR *dirp;
if ((dirp = opendir(argv[1]))== NULL){
fprintf(stderr, "Couldn't open the directory %s: %s \n",argv[1],strerror(errno));
exit(1);
}
unlinkat(dirp,argv[1],AT_REMOVEDIR);
exit(0);
}
在參數給出的路徑是從我要刪除
'unlinkat'返回什麼?通話後有什麼'errno'? – Mat 2014-11-08 18:40:47
您在'opendir()'和'unlinkat()'中使用相同的目錄。所以如果'argv [1]'是'foo/bar',它會嘗試刪除'foo/bar/foo/bar'。 – Barmar 2014-11-08 18:44:13
我改變了它的問題,我複製了一段沒有unlinkat()的代碼。@ Mat錯誤說'壞文件描述符' – tony 2014-11-08 18:46:19