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部署 ➜ ...
随机推荐
- FC网络学习笔记01
1.Fibre Channel 也就是“网状通道”的意思,简称FC,可以称其为FC协议.FC网络或FC互联. 2.像TCP/IP一样,FC协议集同样具备TCP/IP协议集以及以太网中的概念,比如FC交 ...
- [D3] 12. Basic Transitions with D3
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- 假设但是学习java入门,请离开SSH稍远
我觉得有点累了步行上班,我想买一辆自行车.结果去了一看,想2500片.旁边的人说,2500所有最好加一些钱,买一挖电. 遂问电动车价格,3500,决定买.却被告知不如加点钱买小踏板摩托划算.于是看摩托 ...
- Visual Studio2012 Lua插件--BabeLua
之前,找了好久VS2012的Lua插件,没有找到. 今天在http://www.cocoachina.com/bbs/read.php? tid-205043.html 看到了.cocos2dx-qu ...
- memcpy的使用方法总结
1.memcpy 函数用于 把资源内存(src所指向的内存区域) 复制到目标内存(dest所指向的内存区域):拷贝多少个?有一个size变量控制拷贝的字节数:函数原型:void *memcpy(voi ...
- lua 基本
Lua 的语法比较简单,学习起来也比较省力,但功能却并不弱. 所以,我只简单的归纳一下 Lua 的一些语法规则,使用起来方便好查就可以了.估计看完了,就懂得怎么写 Lua 程序了. 在 Lua 中,一 ...
- VC++ 响应回车键的2种方法
众所周知,VC++响应回车键经常用的方法是利用 BOOL PreTranslateMessage(MSG* pMsg) 截取回车键消息,如: if (pMsg->message == WM_KE ...
- Mybaitis配置总结
在mybatis-config.xml中配置分页插件,插件配置必须放在mapper前面 <plugins> <plugin interceptor="com.rrtong. ...
- VS2010调试多进程--医疗His调试中使用
有些时候碰到自己开发的程序嵌入到别人的框架中,而在接口的地方出了问题,而又不方便将自己的模快加入到别人的工程中这个时候VS的附加到进程调试变得不可或缺了,直奔主题 http://msdn.micros ...
- mRemote配置
配置完mRemote后 备份C:\Users\Administrator\AppData\Local\Felix_Deimel\mRemote\confCons.xml文件 覆盖到其他电脑可以直接使用