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部署 ➜ ...
随机推荐
- http://poj.org/problem?id=2253
floyd的应用求每条路径两点之间最大距离的最小值 #include <iostream> #include <cstdio> #include <algorithm&g ...
- 微信支付 V3版
本人小菜鸟一仅仅.为了自我学习和交流PHP(jquery,linux,lamp,shell,javascript,server)等一系列的知识,小菜鸟创建了一个群.希望光临本博客的人能够进来交流. 寻 ...
- Nginx vs Apache--reference
May 14th, 2014 - By Walker Rowe https://anturis.com/blog/nginx-vs-apache/ What is the Nginx web and ...
- webservice 生成代理类
webservice的调用方式有两种: 1. 直接在vs ide中通过web引用的方式,将发布于某个位置的web服务引进到工程里面.这种方式基本上会用vs.net的人都会. 2. 通过vs 命令提 ...
- Android开发之使用意图
意图的用途一般是连接活动,传递数据,从意图返回数据等,下面的例子就是利用意图来交互MainActivity和SecondActivity这两个活动. 效果图如下: 实现代码如下: MainActivi ...
- 利用Gulp实现JSDoc 3的文档编写过程中的实时解析和效果预览
### 利用Gulp实现JSDoc 3的文档编写过程中的实时解析和效果预览 http://segmentfault.com/a/1190000002583569
- Python获取web页面信息
import sys, urllib2 # req = urllib2.Request(sys.argv[1]) req = urllib2.Request('http://www.sina.com. ...
- linux下实现tomcat定时自动重启
tomcat自带的脚本中没有提供直接restart的模式,但是有start和shutdown两种模式.要实现restart模式,实际上只需要判断是否已经启动tomcat,若已经启动则限制性shutdo ...
- ArcGIS 在地图上添加标注
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- phpcms 换域名
修改/caches/configs/system.php里面所有和域名有关的,把以前的老域名修改为新域名就可以了. 进行后台设置->站点管理 对相应的站点的域名进行修改. 更新系统缓存.点击 ...