http server v0.1_http_webapp.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
/*----------------------------------------------------------------- functionname: file_exist
param: NA
return: NA
author: xxxx check if file is exist in webapp
history:
create by xxxx, 2014.1.08, add simple abilities
-------------------------------------------------------------*/
int file_exist(char* url)
{
int ret;
int len = ;
char* path= NULL; if(url == NULL)
return -; len = strlen(url);
if(len <= )
return -; path = (char*)malloc(len);
strncpy(path, url, len); printf("[%s]\n", path);
// remove blanks on head and tailof url
ret = access(path, R_OK);
if(ret == -)
perror("uri not exist"); free(path);
return ret; } long get_file_size(FILE* fs)
{
if(fs == NULL)
return -; fseek(fs, , SEEK_END);
return ftell(fs);
} char *itoa(int num, char *str, int radix)
{
//0的情况
if (num==)
{
str[]='';
str[]='\0';
return str;
} char string[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char* ptr = str;
int i;
int j; while (num)
{
*ptr++ = string[num % radix];
num /= radix; if (num < radix)
{
*ptr++ = string[num];
*ptr = '\0';
break;
}
}
//两边对调
j = ptr - str - ; for (i = ; i < (ptr - str) / ; i++)
{
int temp = str[i];
str[i] = str[j];
str[j--] = temp;
} return str;
} int io_write(int fd, void *usrbuf, int n)
{
int nleft = n;
int nwritten;
char *bufp = usrbuf; while (nleft > ) {
if ((nwritten = write(fd, bufp, nleft)) <= ) {
if (errno == EINTR) /* interrupted by sig handler return */
nwritten = ; /* and call write() again */
else
return -; /* errorno set by write() */
}
nleft -= nwritten;
bufp += nwritten;
}
return n;
}
#ifndef __HTTP_WEBAPP_H
#define __HTTP_WEBAPP_H int file_exist(char* url);
long get_file_size(FILE* fs);
int io_write(int fd, void *usrbuf, int n);
char *itoa(int num, char *str, int radix); #endif
http server v0.1_http_webapp.c的更多相关文章
- http server v0.1_http_reponse.c
#include <string.h> #include <sys/stat.h> #include <sys/mman.h> #include <fcntl ...
- http server v0.1_http_server.c
/**************************************************************** filename: http_server.c author: xx ...
- http server v0.1_http_parse.c
#include <stdio.h> #include <string.h> #include <stdlib.h> #include "mime.h&q ...
- http server v0.1_mime.c
#include <string.h> #include "mime.h" static STR_MIME_MAP mime_map[]= { MIME_MAP(MIM ...
- 用FileZilla Server开FTP
FileZilla(教程)是经典的开源FTP解决方案,包括FileZilla客户端和FileZilla Server.其中,FileZilla Server的功能比起商业软件FTP Serv-U毫不逊 ...
- DNS隧道之DNS2TCP实现——dns2tcpc必须带server IP才可以,此外ssh可以穿过墙的,设置代理上网
我自己的命令: server端: dns2tcpd -F -d 1 -f ./dns2tcpd.conf 输出: 09:08:59 : Debug options.c:97 Add resource ...
- docker 下 安装rancher 笔记
sudo yum update 更新系统环境 curl -sSL https://get.docker.com/ | sh 安装最新docker版本 systemctl start docker.se ...
- 容器基础(七): 使用docker compose部署程序
配置 在上一节的基础上, 增加如下的docker-compose.yml文件, 然后用docker-compose up命令启动容器进行部署: version: " services: s ...
- 容器基础(八): 使用docker swarm部署程序
环境 基于上一节的env/server:v0.1, env/worker:v0.1镜像, 在基于debian8.2的两台机器上测试部署docker swarm. docker service部署 ➜ ...
随机推荐
- 【Leetcode】Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...
- Java基础知识强化之集合框架笔记55:Map集合之HashMap集合(HashMap<Integer,String>)的案例
1. HashMap集合(键是Integer,值是String的案例) 2. 代码示例: package cn.itcast_02; import java.util.HashMap; import ...
- 上传jar包到nexus私服
摘要 通过网页和maven两种方式,上传本地的jar到nexus私服,以及引用jar时,自动引用依赖 1通过网页上传 这种方法只是上传了jar包.通过maven引用当前jar,不能取得jar的依赖 ...
- maven 创建web项目
1,新建一个web项目 2,构建基础目录 web.xml <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web A ...
- HDU-1113(map的运用)
Word Amalgamation Problem Description In millions of newspapers across the United States there is a ...
- SqlSugar框架T4模板的使用
一.T4模板说明 1.T4模板是用来生成Model层实体类的 2.文件后缀为.tt 3.需要修改配置主要有:引用的SqlSugar.dll的位置.生成实体类的位置及生成实体类的命名空间 4.T4模板生 ...
- [功能帮助类] C#取汉字拼音的首字母PinYin帮助类 (转载)
点击下载 PinYin.rar 主要功能就是取汉字拼音的首字母,只要你输入一个汉字,或者是多个汉字就会取出相应的道字母,主要是方便查询使用的 /// <summary> /// 编 码 人 ...
- 2.RABBITMQ 入门 - WINDOWS - 生产和消费消息 一个完整案例
关于安装和配置,见上一篇 1.RABBITMQ 入门 - WINDOWS - 获取,安装,配置 公司有需求,要求使用winform开发这个东西(消息中间件),另外还要求开发一个日志中间件,但是也是要求 ...
- SQL小细节
平时有些小细节,不留意的话很容易得到错误的答案,我们来看下下面的代码,看看你是否能答对呢? ) ,) SELECT @str = '中国CH',@info='MyTest' SELECT [字符串]= ...
- LINUX nohup命令输入输出深浅进出
无论是否将 nohup命令的输出重定向到终端,输出都将附加到当前目录的 nohup.out 文件中.如果当前目录的 nohup.out 文件不可写,输出重定向到 $HOME/nohup.out 文件中 ...