Ai
1 Star 1 Fork 0

kaxia-xia/http文件服务器

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
mstring.c 1.35 KB
Copy Edit Raw Blame History
forestrabbit authored 2023-07-30 20:59 +08:00 . 实现通过http获取文件的功能
#include <stdlib.h>
#include "mstring.h"
MString newString()
{
MString ans;
ans.ptr = 0;
ans.size = 32;
ans.data = (char*)malloc(sizeof(char) * ans.size);
ans.data[0] = 0;
return ans;
}
void freeString(const MString mstring)
{
free(mstring.data);
}
void addChar(MString* mstring, const char ch)
{
if (mstring->ptr == mstring->size - 1)
{
mstring->size <<= 1;
mstring->data = realloc(mstring->data, mstring->size);
}
mstring->data[mstring->ptr++] = ch;
mstring->data[mstring->ptr] = 0;
}
void addRawString(MString* mstring, const char* str)
{
for (int i = 0; str[i] != 0; i++)
{
addChar(mstring, str[i]);
}
}
void addMString(MString* mstring, const MString other)
{
for (int i = 0; i < other.ptr; i++)
{
addChar(mstring, other.data[i]);
}
}
MString numToMStr(unsigned long long num)
{
MString ans = newString();
while (num != 0)
{
addChar(&ans, num % 10 + 0x30);
num /= 10;
}
for (int i = 0; i < ans.ptr / 2; i++)
{
char temp = ans.data[i];
ans.data[i] = ans.data[ans.ptr - 1 - i];
ans.data[ans.ptr - 1 - i] = temp;
}
return ans;
}
MString copyString(const MString mstring)
{
MString ans;
ans.ptr = mstring.ptr;
ans.size = mstring.size;
ans.data = (char*)malloc(sizeof(char) * ans.size);
for (int i = 0; i < ans.ptr; i++)
{
ans.data[i] = mstring.data[i];
}
return ans;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/kaxia-xia/http-file-server.git
git@gitee.com:kaxia-xia/http-file-server.git
kaxia-xia
http-file-server
http文件服务器
main

Search