#include "stdafx.h" #include <iostream> using namespace std; typedef time_t WebsTime; typedef unsigned long ulong; typedef unsigned char uchar; typedef struct WebsMime { char *type; /**< Mime type */ char *ext; /**< File extension */ } WebsMime; typedef struct WebsFileInfo { ulong size; /**< File length */ int isDir; /**< Set if directory */ WebsTime mtime; /**< Modified time */ } WebsFileInfo; typedef long long int int64; typedef int64 Offset; typedef struct WebsRomIndex { char *path; /**< Web page URL path */ uchar *page; /**< Web page data */ int size; /**< Size of web page in bytes */ Offset pos; /**< Current read position */ } WebsRomIndex; #include <stdio.h> #include <assert.h> #define PUBLIC #define PUBLIC_DATA extern #define PRIVATE static typedef const char cchar; typedef size_t ssize; #define MAXINT 256 #include <string.h> PUBLIC ssize slen(cchar *s) { return s ? strlen(s) : 0; } PUBLIC ssize scopy(char *dest, ssize destMax, cchar *src) { ssize len; assert(src); assert(dest); assert(0 < dest && destMax < MAXINT); len = slen(src); if (destMax <= len) { if (destMax > 0) { *dest = '\0'; } return -1; } strcpy(dest, src); return len; } typedef void (*WebsMemNotifier)(ssize size); static WebsMemNotifier memNotifier; PUBLIC void *walloc(ssize num) { void *mem; if ((mem = malloc(num)) == 0) { if (memNotifier) { (memNotifier)(num); } } return mem; } PUBLIC void wfree(void *mem) { if (mem) { free(mem); } } typedef struct WebsBuf { char *buf; /**< Holding buffer for data */ char *servp; /**< Pointer to start of data */ char *endp; /**< Pointer to end of data */ char *endbuf; /**< Pointer to end of buffer */ ssize buflen; /**< Length of ring queue */ ssize maxsize; /**< Maximum size */ int increment; /**< Growth increment */ } WebsBuf; int main() { const char* str = "sdfsfds"; char *abc=(char*)walloc(100); wfree(abc); cout<<slen(str)<<endl; system("PAUSE"); return 0; }
标签:typedef,抽取,mem,代码,PUBLIC,char,include,ssize,goahead From: https://www.cnblogs.com/hshy/p/16727318.html