18 Star 98 Fork 30

liexusong / php-beast

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
tmpfile_file_handler.c 1.45 KB
一键复制 编辑 原始数据 按行查看 历史
maben 提交于 2017-03-22 14:10 . support php5
#include <stdlib.h>
#include <stdio.h>
#include "file_handler.h"
struct tmpfile_handler_ctx {
FILE *fp;
};
int tmpfile_handler_check()
{
return 0;
}
int tmpfile_handler_open(struct file_handler *self)
{
struct tmpfile_handler_ctx *ctx = self->ctx;
ctx->fp = tmpfile();
if (!ctx->fp) {
return -1;
}
return 0;
}
int tmpfile_handler_write(struct file_handler *self, char *buf, int size)
{
struct tmpfile_handler_ctx *ctx = self->ctx;
if (fwrite(buf, 1, size, ctx->fp) == size) {
return 0;
}
return -1;
}
int tmpfile_handler_rewind(struct file_handler *self)
{
struct tmpfile_handler_ctx *ctx = self->ctx;
rewind(ctx->fp);
return 0;
}
FILE *tmpfile_handler_get_fp(struct file_handler *self)
{
struct tmpfile_handler_ctx *ctx = self->ctx;
FILE *retval;
retval = ctx->fp;
ctx->fp = NULL;
return retval;
}
int tmpfile_handler_get_fd(struct file_handler *self)
{
return -1;
}
int tmpfile_handler_destroy(struct file_handler *self)
{
struct tmpfile_handler_ctx *ctx = self->ctx;
if (ctx->fp) {
fclose(ctx->fp);
}
ctx->fp = NULL;
return 0;
}
static struct tmpfile_handler_ctx _ctx = {
NULL
};
struct file_handler tmpfile_handler = {
"tmpfile",
BEAST_FILE_HANDLER_FP,
&_ctx,
tmpfile_handler_check,
tmpfile_handler_open,
tmpfile_handler_write,
tmpfile_handler_rewind,
tmpfile_handler_get_fd,
tmpfile_handler_get_fp,
tmpfile_handler_destroy
};
C
1
https://gitee.com/liexusong/php-beast.git
git@gitee.com:liexusong/php-beast.git
liexusong
php-beast
php-beast
master

搜索帮助