📄 mpr.h
字号:
extern int mprPrintf(MprCtx ctx, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);/* MOB -- NEED DOC */extern int mprErrorPrintf(MprCtx ctx, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);extern int mprStaticPrintf(MprCtx ctx, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);extern int mprPrintfError(MprCtx ctx, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);extern int mprFprintf(MprFile *file, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);/* * Safe string routines */extern char *mprGetWordTok(char *buf, int bufsize, const char *str, const char *delim, const char **tok);extern int mprMemcpy(char *dest, int destMax, const char *src, int nbytes);extern int mprStrcat(char *dest, int max, const char *delim, const char *src, ...);extern int mprStrcpy(char *dest, int destMax, const char *src);extern int mprStrcmpAnyCase(const char *str1, const char *str2);extern int mprStrcmpAnyCaseCount(const char *str1, const char *str2, int len);extern int mprStrlen(const char *src, int max);extern char *mprStrLower(char *str);extern char *mprStrUpper(char *str);extern char *mprStrTrim(char *str, const char *set);extern char *mprStrTok(char *str, const char *delim, char **last);/* * Symbol table */extern MprSymbolTable *mprCreateSymbolTable(MprCtx ctx, int hashSize);extern MprSymbol *mprGetFirstSymbol(MprSymbolTable *table);extern MprSymbol *mprGetNextSymbol(MprSymbolTable *table, MprSymbol *last);extern int mprGetSymbolCount(MprSymbolTable *table);extern MprSymbol *mprInsertSymbol(MprSymbolTable *table, const char *key, void *ptr);extern void *mprLookupSymbol(MprSymbolTable *table, const char *key);extern int mprRemoveSymbol(MprSymbolTable *table, const char *key);/* * File I/O support */extern void mprClose(MprFile *file);extern int mprDelete(MprCtx ctx, const char *path);extern int mprDeleteDir(MprCtx ctx, const char *path);extern int mprGetFileInfo(MprCtx ctx, const char *path, MprFileInfo *info);extern char *mprGets(MprFile *file, char *buf, uint size);extern int mprMakeDir(MprCtx ctx, const char *path, int perms);extern MprFile *mprOpen(MprCtx ctx, const char *path, int omode, int perms);extern int mprPuts(MprFile *file, const char *buf, uint size);extern int mprRead(MprFile *file, void *buf, uint size);extern int mprSeek(MprFile *file, int seekType, long distance);extern int mprWrite(MprFile *file, const void *buf, uint count);extern int mprMakeTempFileName(MprCtx ctx, char *buf, int bufsize, const char *tmpDir);/* * Error handling and logging */extern void mprSetLogHandler(MprCtx ctx, MprLogHandler handler);extern MprLogHandler mprGetLogHandler(MprCtx ctx);extern void mprAssertError(MPR_LOC_DEC(ctx, loc), const char *msg);extern void mprError(MPR_LOC_DEC(ctx, loc), const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);extern void mprFatalError(MPR_LOC_DEC(ctx, loc), const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);extern void mprLog(MprCtx ctx, int level, const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);extern void mprRawLog(MprCtx ctx, const char *fmt, ...);extern void mprStaticAssert(const char *loc, const char *msg);extern void mprStaticError(MPR_LOC_DEC(ctx, loc), const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);extern void mprUserError(MPR_LOC_DEC(ctx, loc), const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);/* * Dynamic Buffering routines */extern MprBuf *mprCreateBuf(MprCtx ctx, int initialSize, int maxSize);extern char *mprStealBuf(MprCtx ctx, MprBuf *bp);extern void mprAddNullToBuf(MprBuf *bp);extern void mprAdjustBufStart(MprBuf *bp, int size);extern void mprAdjustBufEnd(MprBuf *bp, int size);extern void mprCopyBufDown(MprBuf *bp);extern void mprFlushBuf(MprBuf *bp);extern int mprGetCharFromBuf(MprBuf *bp);extern int mprGetBlockFromBuf(MprBuf *bp, uchar *buf, int len);extern int mprGetBufLength(MprBuf *bp);extern int mprGetBufLinearSpace(MprBuf *bp);extern int mprGetBufLinearData(MprBuf *bp);extern char *mprGetBufOrigin(MprBuf *bp);extern int mprGetBufSize(MprBuf *bp);extern int mprGetBufSpace(MprBuf *bp);extern char *mprGetBufStart(MprBuf *bp);extern char *mprGetBufEnd(MprBuf *bp);extern int mprInsertCharToBuf(MprBuf *bp, int c);extern int mprLookAtNextCharInBuf(MprBuf *bp);extern int mprLookAtLastCharInBuf(MprBuf *bp);extern int mprPutCharToBuf(MprBuf *bp, int c);extern int mprPutBlockToBuf(MprBuf *bp, const char *str, int size);extern int mprPutIntToBuf(MprBuf *bp, int i);extern int mprPutStringToBuf(MprBuf *bp, const char *str);extern int mprPutFmtStringToBuf(MprBuf *bp, const char *fmt, ...);extern int mprRefillBuf(MprBuf *bp);extern void mprResetBufIfEmpty(MprBuf *bp);extern void mprSetBufSize(MprBuf *bp, int initialSize, int maxSize);extern MprBufProc mprGetBufRefillProc(MprBuf *bp);extern void mprSetBufRefillProc(MprBuf *bp, MprBufProc fn, void *arg);/* * General other xPlatform routines */extern const char *mprGetBaseName(const char *name);extern bool mprGetDebugMode(MprCtx ctx);extern char *mprGetDirName(char *buf, int bufsize, const char *path);extern char *mprGetFullPathName(char *buf, int buflen, const char *path);extern int mprGetLogLevel(MprCtx ctx);extern int mprGetOsError();extern int mprMakeArgv(MprCtx ctx, const char *prog, const char *cmd, char ***argv, int *argc);extern int mprMakeDirPath(MprCtx ctx, const char *path);extern void mprSetDebugMode(MprCtx ctx, bool on);extern void mprSetLogLevel(MprCtx ctx, int level);extern void mprSleep(MprCtx ctx, int msec);extern void mprSetShell(MprCtx ctx, void *shell);extern void *mprGetShell(MprCtx ctx);extern void mprSetClassId(MprCtx ctx, uint classId);extern uint mprGetClassId(MprCtx ctx);#if BREWextern void mprSetDisplay(MprCtx ctx, void *display);extern void *mprGetDisplay(MprCtx ctx);extern void mprSetFileMgr(MprCtx ctx, void *fileMgr);extern void *mprGetFileMgr(MprCtx ctx);#elseextern char *mprInetToStr(char *buf, int size, const struct in_addr in);#endif/* * Memory allocation */extern MprApp *mprAllocInit(MprAllocCback cback);extern void mprAllocTerm(MprApp *app);extern void mprAllocAbort();extern void *mprAllocBlock(MPR_LOC_DEC(ctx, loc), uint size);extern void *mprAllocZeroedBlock(MPR_LOC_DEC(ctx, loc), uint size);extern void *mprReallocBlock(MPR_LOC_DEC(ctx, loc), void *ptr, uint size);extern int mprFree(void *ptr);extern int mprStealAllocBlock(MPR_LOC_DEC(ctx, loc), const void *ptr);extern void *mprMemdupInternal(MPR_LOC_DEC(ctx, loc), const void *ptr, uint size);extern char *mprStrndupInternal(MPR_LOC_DEC(ctx, loc), const char *str, uint size);extern char *mprStrdupInternal(MPR_LOC_DEC(ctx, loc), const char *str);extern void *mprSlabAllocBlock(MPR_LOC_DEC(ctx, loc), uint size, uint inc);extern void *mprSlabAllocZeroedBlock(MPR_LOC_DEC(ctx, loc), uint size, uint inc);extern uint mprGetAllocBlockSize(MprCtx ctx);extern uint mprGetAllocBlockCount(MprCtx ctx);extern uint mprGetAllocBlockMemory(MprCtx ctx);extern void *mprGetAllocParent(MprCtx ctx);extern uint mprGetAllocatedMemory(MprCtx ctx);extern uint mprGetPeakAllocatedMemory(MprCtx ctx);extern uint mprGetAllocatedSlabMemory(MprCtx ctx);extern int mprIsAllocBlockValid(MprCtx ctx);extern int mprStackCheck(MprCtx ctx);extern int mprStackSize(MprCtx ctx);extern int mprGetAllocErrors(MprCtx ctx);extern void mprClearAllocErrors(MprCtx ctx);extern MprDestructor mprSetDestructor(MprCtx ctx, MprDestructor destructor);extern MprAllocCback mprSetAllocCallback(MprApp *app, MprAllocCback cback);extern void mprSetAllocLimits(MprApp *app, uint redLine, uint maxMemory);#if BLD_FEATURE_ALLOC_STATSextern MprSlabStats *mprGetSlabAllocStats(MprApp *app, int slabIndex);extern MprAllocStats *mprGetAllocStats(MprApp *app);extern void mprPrintAllocReport(MprApp *app, bool doBlocks, const char *msg);#endif#if BLD_DEBUGextern int mprPrintAllocBlocks(MprCtx ctx, int indent);extern const char *mprGetAllocLocation(MprCtx ptr);#endifextern int mprValidateBlock(MprCtx ctx);extern int mprValidateAllocTree(MprCtx ptr);extern void mprSetRequiredAlloc(MprCtx ptr, bool recurse);/* * Sprintf style allocators */extern int mprAllocSprintf(MPR_LOC_DEC(ctx, loc), char **buf, int maxSize, const char *fmt, ...) PRINTF_ATTRIBUTE(5,6);extern int mprAllocVsprintf(MPR_LOC_DEC(ctx, loc), char **buf, int maxSize, const char *fmt, va_list arg) PRINTF_ATTRIBUTE(5,0);extern int mprAllocMemcpy(MPR_LOC_DEC(ctx, loc), char **dest, int destMax, const void *src, int nbytes);extern int mprAllocStrcat(MPR_LOC_DEC(ctx, loc), char **dest, int max, const char *delim, const char *src, ...);extern int mprAllocStrcpy(MPR_LOC_DEC(ctx, loc), char **dest, int max, const char *src);extern int mprReallocStrcat(MPR_LOC_DEC(ctx, loc), char **dest, int max, int existingLen, const char *delim, const char *src, ...);/* * MACROS: These are the convenience macros to automatically supply file * names and line numbers when debugging. */ #define mprNew(ctx) new(MPR_LOC_ARGS(ctx))#define mprAlloc(ctx, size) mprAllocBlock(MPR_LOC_ARGS(ctx), size)#define mprAllocZeroed(ctx, size) mprAllocZeroedBlock(MPR_LOC_ARGS(ctx), size)#define mprSlabAlloc(ctx, size, inc) \ ((type*) mprSlabAllocBlock(MPR_LOC_ARGS(ctx), size, inc))#define mprSlabAllocZeroed(ctx, size, inc) \ ((type*) mprSlabAllocBlock(MPR_LOC_ARGS(ctx), size, inc))#define mprRealloc(ctx, ptr, size) mprReallocBlock(MPR_LOC_ARGS(ctx), ptr, size)#define mprMemdup(ctx, ptr, size) \ mprMemdupInternal(MPR_LOC_ARGS(ctx), ptr, size)#define mprStrdup(ctx, str) mprStrdupInternal(MPR_LOC_ARGS(ctx), str)#define mprStrndup(ctx, str, size) mprStrndupDebug(MPR_LOC_ARGS(ctx), str, size)/* * Allocate type macros */#define mprAllocType(ctx, type) \ ((type*) mprAllocBlock(MPR_LOC_ARGS(ctx), sizeof(type)))#define mprAllocTypeZeroed(ctx, type) \ ((type*) mprAllocZeroedBlock(MPR_LOC_ARGS(ctx), sizeof(type)))#define mprSlabAllocType(ctx, type, inc) \ ((type*) mprSlabAllocBlock(MPR_LOC_ARGS(ctx), sizeof(type), inc))#define mprSlabAllocTypeZeroed(ctx, type, inc) \ ((type*) mprSlabAllocZeroedBlock(MPR_LOC_ARGS(ctx), sizeof(type), \ inc))/* * Multithread locking */#if BLD_FEATURE_MULTITHREADextern void mprInitThreads(MprApp *app);extern void mprTermThreads(MprApp *app);extern MprLock *mprCreateLock(MprCtx ctx);extern void mprDestroyLock(MprLock *lock);extern void mprLock(MprLock *lock);extern int mprTryLock(MprLock *lock);extern void mprUnlock(MprLock *lock);extern void mprGlobalLock(MprCtx ctx);extern void mprGlobalUnlock(MprCtx ctx);extern int mprGetCurrentThreadID();#else/* * Disable multithreading */#define mprInitThreads(ctx, app)#define mprTermThreads(app)#define mprCreateLock(ctx)#define mprDestroyLock(lock)#define mprLock(lock)#define mprTryLock(lock)#define mprUnlock(lock)#define mprGlobalLock(app)#define mprGlobalUnlock(app)#define mprGetCurrentThreadID()#endif/* * Time */extern MprTime *mprGetTime(MprCtx ctx, MprTime *tp);extern int mprGetTimeRemaining(MprCtx ctx, MprTime mark, uint timeout);extern int mprGetElapsedTime(MprCtx ctx, MprTime mark);extern int mprCompareTime(MprTime *t1, MprTime *t2);extern uint mprSubtractTime(MprTime *t1, MprTime *t2);extern void mprAddElapsedToTime(MprTime *time, uint elapsed);#if !BREWextern int mprAsctime(MprCtx ctx, char *buf, int bufsize, const struct tm *timeptr);extern int mprCtime(MprCtx ctx, char *buf, int bufsize, const time_t *timer);extern struct tm *mprLocaltime(MprCtx ctx, struct tm *timep, time_t *now);extern struct tm *mprGmtime(MprCtx ctx, time_t* now, struct tm *timep);extern int mprRfcTime(MprCtx ctx, char *buf, int bufsize, const struct tm *timep);#endif /* !BREW *//* * Host name */extern struct hostent* mprGetHostByName(MprCtx ctx, const char *name);#if WINextern int mprReadRegistry(MprCtx ctx, char **buf, int max, const char *key, const char *val);extern int mprWriteRegistry(MprCtx ctx, const char *key, const char *name, const char *value);#endif#ifdef __cplusplus}#endif#endif /* _h_MPR *//* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim:tw=78 * vim600: sw=4 ts=4 fdm=marker * vim<600: sw=4 ts=4 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -