- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
My last question作为背景。我试图环绕“fopen()”,但 gcc 给了我这个错误,而“remove()”没有问题。
错误:“fopen”的类型冲突fopen(const char *路径名, const char *模式)^在 file_io_operation_interception.c:2:0 包含的文件中:/usr/include/stdio.h:272:14:注意:之前的“fopen”声明是这里extern FILE *fopen (const char *__restrict __filename,
这是代码。
#define _GNU_SOURCE
#include <stdio.h>
#include <dlfcn.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#define PORT 8080
#define MAXLINE 1024
static int (*real_fopen)(const char *pathname, const char *mode) = NULL;
static int (*real_remove)(const char *filename) = NULL;
static int (*real_close)(int fd) = NULL;
__attribute__((constructor))
void
my_lib_init(void)
{
real_fopen = dlsym(RTLD_NEXT,"fopen");
real_remove = dlsym(RTLD_NEXT,"remove");
real_close = dlsym(RTLD_NEXT,"close");
}
int
fopen(const char *pathname, const char *mode)
{
int fd;
// do whatever special stuff ...
fd = real_fopen(pathname, mode);
printf("open worked!\n");
char message[200];
char fidString[10];
sprintf(fidString, "%d ", fd);
strcat(message, fidString);
strcat(message, pathname);
sendMessage(message);
// do whatever special stuff ...
return fd;
}
int
remove(const char *filename)
{
int ret;
/*
if (real_remove == NULL)
real_remove = dlsym(RTLD_NEXT,"remove");
*/
// do whatever special stuff ...
printf("remove worked!\n");
sendMessage("remove message sent");
ret = real_remove(filename);
// do whatever special stuff ...
return ret;
}
int
close(int fd)
{
int ret;
/*
if (real_close == NULL)
real_close = dlsym(RTLD_NEXT,"close");
*/
// do whatever special stuff ...
printf("close worked!\n");
ret = real_close(fd);
// do whatever special stuff ...
return ret;
}
int
sendMessage(char *message)
{
int sockfd;
struct sockaddr_in servaddr;
// Creating socket file descriptor
if ( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) {
perror("socket creation failed");
exit(EXIT_FAILURE);
}
memset(&servaddr, 0, sizeof(servaddr));
// Filling server information
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(PORT);
servaddr.sin_addr.s_addr = INADDR_ANY;
int n, len;
sendto(sockfd, (const char *)message, strlen(message),
MSG_CONFIRM, (const struct sockaddr *) &servaddr,
sizeof(servaddr));
printf("message sent\n");
close(sockfd);
return 0;
}
“remove()”函数工作正常,但“fopen()”则不行。它们都在 stdio.h 中声明。但是,为什么会出现这种差异呢?
最佳答案
我已经找到解决办法了。 “fopen()”的返回值应该是FILE *,但我错误地使用了int。
关于c - 尝试覆盖 'fopen()' 但 GCC 给出 "error: conflicting types for ' fopen'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54249547/
我想在我的 cpp 函数中调用 fopen,但是,Rcpp 总是提示“没有匹配的函数来调用‘fopen’”。所以完全复制了 https://github.com/hadley/xml2/blob/93
我想在我的 cpp 函数中调用 fopen,但是,Rcpp 总是提示“没有匹配的函数来调用‘fopen’”。所以完全复制了 https://github.com/hadley/xml2/blob/93
我正在使用本教程 http://papermashup.com/caching-dynamic-php-pages-easily/用于缓存页面 /* Heres where you put your
我在 Wordpress 上工作,我对 PHP 几乎一无所知。我正在尝试让带有帖子摘录的滚动条正常工作,但它使用了 fopen() 但它在我客户的主机上已关闭。 $f = fopen( $url, '
我有一个基本程序,旨在复制 bash 的 cp 命令的功能。我正在为 UNIX 和 Windows 开发一个副本。我的 UNIX 版本运行良好,但是,我发现 Windows 不支持 fopen() 的
在我的网站上,用户填写表格进行注册,然后该信息会添加到数据库中。我也试图将信息写入 CSV 文件。到目前为止我的代码给了我这个错误: 警告:fopen() [function.fopen]:第 122
我正在尝试学习 C。函数 Foo 的目标是接受一个字符串,更改其中的一些字符,然后查看是否存在具有该名称的文件。如果存在这样的文件,则在 STDOUT 上打印它的内容。 听起来很简单而且应该很简单,但
我目前有一些未压缩的代码读取文件,它使用以下方法在C++中读取文件 FILE* id = fopen("myfile.dat", "r"); 获得id后,代码的不同部分使用fread、fseek等访问
My last question作为背景。我试图环绕“fopen()”,但 gcc 给了我这个错误,而“remove()”没有问题。 错误:“fopen”的类型冲突fopen(const char *
好的,所以我正在学习 Docker,并且我正在尝试部署一个带有指向我的服务器的子域(其域是从另一个提供商处购买的)的测试应用程序。服务器已经具有非 dockerized Nginx 设置,可以完美地服
我需要在我的系统 verilog 代码中打开一个文件,我需要知道它对我的相对路径才能使用 $fopen。所以首先,我需要知道我的立场。有没有办法知道我当前的目录路径? (通过使用 $display 或
我的网站被一个脚本小子攻击得非常成功。在自动的基础上,一个隐藏的脚本在我的服务器上被访问,导致我所有的 index.php 文件被修改,并在它们的顶部添加一个 iframe(base 64 编码)。
我尝试通过fopen("serial port path", "+w")打开串口 并通过fileno()获取文件描述符。 之后,我调用了 tcsetattr() 但它生成了一个错误,显示 Inappr
在下面的声明中: $handle = fopen('./readme.txt'); $handle 是什么变量?是 bool 值还是什么? 在运行这两个不同的语句后我有疑问: if($handle)
我是一名 PHP 学习者,我正在处理文件,但我无法在自己的服务器中打开文件,因为出现“权限被拒绝”错误。我正在使用 fopen()功能:fopen('file.txt', 'r+'); 我在 Cent
我需要打开一个文件,替换一些内容(12345 为 77348)并保存。据我所知 $cookie_file_path=$path."/cookies/shipping-cookie".$unique;
我有一个巨大的二进制文件,有 2148181087 字节 (> 2gb) 我正在尝试执行 fopen (file, "r") 但失败了 Can not open: xyz file (Value to
我的桌面上有一个名为 fun 的文本文件,但是当我通过时: FILE* fp; if((fp = fopen("/Users//Desktop/fun", "r")) == NULL) { p
我有一个名为 denem.txt 的文件并且有内容 123456789 123456789 123456789 当我们以“a+b”模式打开文件时,PHP 应该将指针指向文件末尾,这意味着当我尝试使用
我想知道是否有人可以通过 Matlab fopen 命令阐明以下问题: >> [stat myjob] = unix('echo $PBS_NODEFILE'); % gets PBS file na
我是一名优秀的程序员,十分优秀!