当我尝试编译使用gets()GCC函数的C代码时,
我明白了
警告:
(.text + 0x34):警告:`gets'函数很危险,不应该使用.
我记得这与堆栈保护和安全性有关,但我不确定为什么?
有人可以帮我删除这个警告并解释为什么会有这样的使用警告gets()?
如果gets()是如此危险,为什么我们不能删除它?
这是我写的一个C程序,用于递归导航和输出目录和常规文件.它在我的Linux机器上编译并运行良好.但是在Solaris上,dit->d_type == 8检查和其他类似检查不起作用,因为没有d_type字段.我已经阅读过这个问题的答案是使用S_ISREG()和S_ISDIR()宏,但它们并不能完全按照我目前的代码中的方式工作.我注释掉了在我的Linux机器上运行的行.
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <dirent.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
void helper(DIR *, struct dirent *, struct stat, char *, int, char **);
void dircheck(DIR *, struct dirent *, struct stat, char *, int, char **);
int main(int argc, char *argv[]){
DIR *dip;
struct dirent *dit;
struct stat statbuf;
char currentPath[FILENAME_MAX];
int depth = 0; /*Used to correctly space output*/
/*Open Current Directory*/ …Run Code Online (Sandbox Code Playgroud) 我一直很好奇remLinux在工作中如何编写我自己的C代码可以删除文件但是当我搜索答案时,我只得到了使用remove()系统调用的程序.
有没有其他方法可以不使用系统调用来编写自己的代码来完成这项工作?
我已经完成了通过C文件复制文件但无法找到通过C删除文件的解决方案.