📄 wrapper.c
字号:
#ifndef _WRAPPER_C_#define _WRAPPER_C_ 0#include "SysHeaders.h"#include "Error.c"FILE *Fopen( const char *path,const char *mode ){ FILE *fp; if( (fp = fopen(path,mode)) == NULL ) err_sys("Error occurred when opening file!"); return fp;}void Fwrite( const void *ptr,size_t size,size_t nmemb,FILE *stream ){ if( fwrite(ptr,size,nmemb,stream) != 1 ) err_sys("Error occurred when writing file!"); }/* I don't kown why we can't use the wrapper function here size_t Fread( const void *ptr,size_t size,size_t nmemb,FILE *stream ){ return fread(ptr,size,nmemb,stream);}*/void Fclose( FILE *stream ){ if( fclose(stream) != 0 ) err_sys("Error occurred when closing file!");}intset_concurrency(int level){#ifdef HAVE_THR_SETCONCURRENCY_PROTO int thr_setconcurrency(int); return(thr_setconcurrency(level));#else return(0);#endif}voidSet_concurrency(int level){ if (set_concurrency(level) != 0) err_sys("set_concurrency error");}voidPthread_create(pthread_t *tid, const pthread_attr_t *attr, void * (*func)(void *), void *arg){ int n; if ( (n = pthread_create(tid, attr, func, arg)) == 0) return; errno = n; err_sys("pthread_create error");}voidPthread_join(pthread_t tid, void **status){ int n; if ( (n = pthread_join(tid, status)) == 0) return; errno = n; err_sys("pthread_join error");}voidPthread_mutexattr_init(pthread_mutexattr_t *attr){ int n; if ( (n = pthread_mutexattr_init(attr)) == 0) return; errno = n; err_sys("pthread_mutexattr_init error");}voidPthread_mutexattr_destroy(pthread_mutexattr_t *attr){ int n; if ( (n = pthread_mutexattr_destroy(attr)) == 0) return; errno = n; err_sys("pthread_mutexattr_destroy error");}#ifdef _POSIX_THREAD_PROCESS_SHAREDvoidPthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int flag){ int n; if ( (n = pthread_mutexattr_setpshared(attr, flag)) == 0) return; errno = n; err_sys("pthread_mutexattr_setpshared error");}#endifvoidPthread_mutex_init(pthread_mutex_t *mptr, pthread_mutexattr_t *attr){ int n; if ( (n = pthread_mutex_init(mptr, attr)) == 0) return; errno = n; err_sys("pthread_mutex_init error");}/* include Pthread_mutex_lock */voidPthread_mutex_lock(pthread_mutex_t *mptr){ int n; if ( (n = pthread_mutex_lock(mptr)) == 0) return; errno = n; err_sys("pthread_mutex_lock error");}/* end Pthread_mutex_lock */intPthread_mutex_trylock(pthread_mutex_t *mptr){ return pthread_mutex_trylock(mptr);}voidPthread_mutex_unlock(pthread_mutex_t *mptr){ int n; if ( (n = pthread_mutex_unlock(mptr)) == 0) return; errno = n; err_sys("pthread_mutex_unlock error");}voidPthread_condattr_init(pthread_condattr_t *attr){ int n; if ( (n = pthread_condattr_init(attr)) == 0) return; errno = n; err_sys("pthread_condattr_init error");}voidPthread_condattr_destroy(pthread_condattr_t *attr){ int n; if ( (n = pthread_condattr_destroy(attr)) == 0) return; errno = n; err_sys("pthread_condattr_destroy error");}#ifdef _POSIX_THREAD_PROCESS_SHAREDvoidPthread_condattr_setpshared(pthread_condattr_t *attr, int flag){ int n; if ( (n = pthread_condattr_setpshared(attr, flag)) == 0) return; errno = n; err_sys("pthread_condattr_setpshared error");}#endifvoidPthread_cond_signal(pthread_cond_t *cptr){ int n; if ( (n = pthread_cond_signal(cptr)) == 0) return; errno = n; err_sys("pthread_cond_signal error");}voidPthread_cond_wait(pthread_cond_t *cptr, pthread_mutex_t *mptr){ int n; if ( (n = pthread_cond_wait(cptr, mptr)) == 0) return; errno = n; err_sys("pthread_cond_wait error");}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -