type
stringclasses
5 values
content
stringlengths
9
163k
functions
void CRYPTO_THREADID_set_numeric(CRYPTO_THREADID *id, unsigned long val) { memset(id, 0, sizeof(*id)); id->val = val; }
functions
void CRYPTO_THREADID_set_pointer(CRYPTO_THREADID *id, void *ptr) { unsigned char *dest = (void *)&id->val; unsigned int accum = 0; unsigned char dnum = sizeof(id->val); memset(id, 0, sizeof(*id)); id->ptr = ptr; if (sizeof(id->val) >= sizeof(id->ptr)) { /* * 'ptr' can be embedded in 'val' without loss of uniqueness */ id->val = (unsigned long)id->ptr; return; }
functions
void CRYPTO_THREADID_current(CRYPTO_THREADID *id) { if (threadid_callback) { threadid_callback(id); return; }
functions
int CRYPTO_THREADID_cmp(const CRYPTO_THREADID *a, const CRYPTO_THREADID *b) { return memcmp(a, b, sizeof(*a)); }
functions
void CRYPTO_THREADID_cpy(CRYPTO_THREADID *dest, const CRYPTO_THREADID *src) { memcpy(dest, src, sizeof(*src)); }
functions
long CRYPTO_THREADID_hash(const CRYPTO_THREADID *id) { return id->val; }
functions
long CRYPTO_thread_id(void) { unsigned long ret = 0; if (id_callback == NULL) { # if defined(OPENSSL_SYS_WIN32) ret = (unsigned long)GetCurrentThreadId(); # elif defined(GETPID_IS_MEANINGLESS) ret = 1L; # else ret = (unsigned long)getpid(); # endif }
includes
#include <sys/socket.h>
includes
#include <netinet/in.h>
includes
#include <arpa/inet.h>
includes
#include <sys/wait.h>
includes
#include <unistd.h>
includes
#include <stdio.h>
includes
#include <stdlib.h>
includes
#include <string.h>
includes
#include <signal.h>
includes
#include <errno.h>
includes
#include <sys/stat.h>
includes
#include <sys/mman.h>
includes
#include <fcntl.h>
functions
int writeTo(int fd, char * string) { return write(fd, string, strlen(string)); }
functions
void err_dump(int fd, int status, char * err_msg) { char line[LINE_SIZE]; snprintf(line, LINE_SIZE, "HTTP/1.1 %d %s\r\n\r\n", status, err_msg); writeTo(fd, line); snprintf(line, LINE_SIZE, "ERROR: %d\r\n", status); writeTo(fd, line); snprintf(line, LINE_SIZE, "ERROR MESSAGE: %s\r\n\r\n", err_msg); writeTo(fd, line); }
functions
void sig_int(int signo) { exit(0); }
functions
void sig_child(int signo) { signal(SIGCHLD, sig_child); while (waitpid(-1, NULL, WNOHANG) > 0) ; }
functions
void initServer() { /* 忽略 sigpipe 信号 */ signal(SIGPIPE, SIG_IGN); signal(SIGINT, sig_int); signal(SIGCHLD, sig_child); }
functions
int open_listenfd(int port) { int sockfd, res; struct sockaddr_in addr; /* 创建socket */ sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) { fprintf(stderr, "socket error\n"); exit(1); }
functions
void handleUri(int fd, const char * uri) { char whole_uri[URI_LEN] = DOCUMENT_ROOT; int ffd; /* 文件描述符 */ struct stat f_statue; char * buf; if (uri[0] == '/') { uri += 1; }
functions
void doit(int fd) { char line[LINE_SIZE]; char method[10], uri[URI_LEN], version[10]; rio_t rio; rio_init(&rio, fd); if (rio_readline(&rio, line, LINE_SIZE) <= 0) { err_dump(fd, 400, "Bad Request"); return; }
functions
else if (pid == 0) { /* child */ close(sockfd); doit(fd); printf("结束 %d: %s\n", num, client_ip); exit(0); }
main
int main() { int fd, sockfd, pid, num; socklen_t client_len; struct sockaddr_in client_addr; char * client_ip; initServer(); sockfd = open_listenfd(PORT); num = 0; /* 等待请求 */ while (1) { while ((fd = accept(sockfd, (struct sockaddr *)&client_addr, &client_len)) < 0) { if (errno != EINTR) { /* 不是被信号处理函数中断 */ fprintf(stderr, "accept error\n"); exit(1); }
includes
#include <assert.h>
includes
#include <math.h>
includes
#include <stdarg.h>
includes
#include <stdio.h>
includes
#include <stdlib.h>
includes
#include <string.h>
includes
#include <time.h>
defines
#define RETURN_VALUE switch ( self->type ) { \
defines
#define REPLACE( match, value ) \
defines
#define STRINGIFY_DATE_SECTION( format, part, spacer ) \
structs
struct _TOMLStringifyData { TOMLError *error; int bufferSize; int bufferIndex; char *buffer; int tableNameDepth; int tableNameStackSize; TOMLString **tableNameStack; };
functions
TOMLRef TOML_alloc( TOMLType type ) { switch ( type ) { case TOML_TABLE: return TOML_allocTable( NULL, NULL ); case TOML_ARRAY: return TOML_allocArray( TOML_NOTYPE ); case TOML_STRING: return TOML_allocString( "" ); case TOML_INT: return TOML_allocInt( 0 ); case TOML_DOUBLE: return TOML_allocDouble( 0 ); case TOML_BOOLEAN: return TOML_allocBoolean( 0 ); case TOML_DATE: return TOML_allocEpochDate( 0 ); default: return NULL; }
functions
int _TOML_isLeapYear( int year ) { if ( year % 400 == 0 ) { return 1; }
functions
else if ( year % 100 == 0 ) { return 0; }
functions
else if ( year % 4 == 0 ) { return 1; }
functions
TOMLRef TOML_copy( TOMLRef self ) { TOMLBasic *basic = (TOMLBasic *) self; if ( basic->type == TOML_TABLE ) { TOMLTable *table = (TOMLTable *) self; TOMLTable *newTable = malloc( sizeof(TOMLTable) ); newTable->type = TOML_TABLE; newTable->keys = TOML_copy( table->keys ); newTable->values = TOML_copy( table->values ); return newTable; }
functions
else if ( basic->type == TOML_ARRAY ) { TOMLArray *array = (TOMLArray *) self; TOMLArray *newArray = malloc( sizeof(TOMLArray) ); newArray->type = TOML_ARRAY; newArray->memberType = array->memberType; int i; for ( i = 0; i < array->size; ++i ) { TOMLArray_append( newArray, TOML_copy( TOMLArray_getIndex( array, i ) ) ); }
functions
else if ( basic->type == TOML_STRING ) { TOMLString *string = (TOMLString *) self; TOMLString *newString = malloc( sizeof(TOMLString) + string->size + 1 ); newString->type = TOML_STRING; newString->size = string->size; strncpy( newString->content, string->content, string->size + 1 ); return newString; }
functions
else if ( basic->type == TOML_INT || basic->type == TOML_DOUBLE ) { TOMLNumber *number = (TOMLNumber *) self; TOMLNumber *newNumber = malloc( sizeof(TOMLNumber) ); newNumber->type = number->type; // newNumber->numberType = number->numberType; memcpy( newNumber->bytes, number->bytes, 8 ); return newNumber; }
functions
else if ( basic->type == TOML_BOOLEAN ) { TOMLBoolean *boolean = (TOMLBoolean *) self; TOMLBoolean *newBoolean = malloc( sizeof(TOMLBoolean) ); newBoolean->type = boolean->type; newBoolean->isTrue = boolean->isTrue; return newBoolean; }
functions
else if ( basic->type == TOML_DATE ) { TOMLDate *date = (TOMLDate *) self; TOMLDate *newDate = malloc( sizeof(TOMLDate) ); *newDate = *date; return newDate; }
functions
else if ( basic->type == TOML_ERROR ) { TOMLError *error = (TOMLError *) self; TOMLError *newError = malloc( sizeof(TOMLError) ); newError->type = TOML_ERROR; newError->code = error->code; newError->lineNo = error->lineNo; newError->line = _TOML_cstringCopy( error->line ); newError->message = _TOML_cstringCopy( error->message ); newError->fullDescription = _TOML_cstringCopy( error->fullDescription ); return newError; }
functions
void TOML_free( TOMLRef self ) { TOMLBasic *basic = (TOMLBasic *) self; if ( basic->type == TOML_TABLE ) { TOMLTable *table = (TOMLTable *) self; TOML_free( table->keys ); TOML_free( table->values ); }
functions
else if ( basic->type == TOML_ARRAY ) { TOMLArray *array = (TOMLArray *) self; int i; for ( i = 0; i < array->size; ++i ) { TOML_free( array->members[ i ] ); }
functions
else if ( basic->type == TOML_ERROR ) { TOMLError *error = (TOMLError *) self; free( error->line ); free( error->message ); free( error->fullDescription ); }
functions
int TOML_isType( TOMLRef self, TOMLType type ) { TOMLBasic *basic = (TOMLBasic *) self; return basic->type == type; }
functions
int TOML_isNumber( TOMLRef self ) { TOMLBasic *basic = (TOMLBasic *) self; return basic->type == TOML_INT || basic->type == TOML_DOUBLE; }
functions
TOMLRef TOML_find( TOMLRef self, ... ) { TOMLBasic *basic = self; va_list args; va_start( args, self ); char *key; do { if ( basic->type == TOML_TABLE ) { key = va_arg( args, char * ); if ( key == NULL ) { break; }
functions
else if ( basic->type == TOML_ARRAY ) { key = va_arg( args, char * ); if ( key == NULL ) { break; }
functions
TOMLRef TOMLTable_getKey( TOMLTable *self, char *key ) { int keyLength = strlen( key ); int i; for ( i = 0; i < self->keys->size; ++i ) { TOMLString *tableKey = TOMLArray_getIndex( self->keys, i ); int minSize = keyLength < tableKey->size ? keyLength : tableKey->size; if ( strncmp( tableKey->content, key, minSize + 1 ) == 0 ) { return TOMLArray_getIndex( self->values, i ); }
functions
void TOMLTable_setKey( TOMLTable *self, char *key, TOMLRef value ) { int keyLength = strlen( key ); int i; for ( i = 0; i < self->keys->size; ++i ) { TOMLString *tableKey = TOMLArray_getIndex( self->keys, i ); int minSize = keyLength < tableKey->size ? keyLength : tableKey->size; if ( strncmp( tableKey->content, key, minSize ) == 0 ) { TOMLArray_setIndex( self->values, i, value ); return; }
functions
TOMLRef TOMLArray_getIndex( TOMLArray *self, int index ) { return self->members && self->size > index ? self->members[ index ] : NULL; }
functions
void TOMLArray_setIndex( TOMLArray *self, int index, TOMLRef value ) { if ( index < self->size ) { TOML_free( self->members[ index ] ); self->members[ index ] = value; }
functions
void TOMLArray_append( TOMLArray *self, TOMLRef value ) { TOMLRef *oldMembers = self->members; self->members = malloc( ( self->size + 1 ) * sizeof(TOMLRef) ); int i = 0; for ( ; i < self->size; ++i ) { self->members[ i ] = oldMembers[ i ]; }
functions
int TOML_toInt( TOMLNumber *self ) { RETURN_VALUE; }
functions
double TOML_toDouble( TOMLNumber *self ) { RETURN_VALUE; }
functions
tm TOML_toTm( TOMLDate *self ) { return *gmtime( &self->sinceEpoch ); }
functions
int TOML_toBoolean( TOMLBoolean *self ) { return self->isTrue; }
functions
void TOML_strcpy( char *buffer, TOMLString *self, int size ) { if ( self->type != TOML_STRING ) { buffer[0] = 0; }
functions
int TOML_load( char *filename, TOMLTable **dest, TOMLError *error ) { assert( *dest == NULL ); FILE *fd = fopen( filename, "r" ); if ( fd == NULL ) { if ( error ) { error->code = TOML_ERROR_FILEIO; error->lineNo = -1; error->line = NULL; int messageSize = strlen( TOMLErrorDescription[ error->code ] ); error->message = malloc( messageSize + 1 ); strcpy( error->message, TOMLErrorDescription[ error->code ] ); error->message[ messageSize ] = 0; int fullDescSize = messageSize + strlen( filename ) + 8; error->fullDescription = malloc( fullDescSize + 1 ); snprintf( error->fullDescription, fullDescSize, "%s File: %s", error->message, filename ); }
functions
int TOML_parse( char *buffer, TOMLTable **dest, TOMLError *error ) { assert( *dest == NULL ); int hTokenId; TOMLToken token = { 0, NULL, NULL, buffer, 0, buffer, NULL }
functions
void _TOML_stringifyPushName( struct _TOMLStringifyData *self, TOMLRef src ) { if ( self->tableNameDepth >= self->tableNameStackSize ) { self->tableNameStack = _TOML_increaseNameStack( self->tableNameStack, &( self->tableNameStackSize ) ); }
functions
void _TOML_stringifyPopName( struct _TOMLStringifyData *self ) { self->tableNameDepth--; self->tableNameStack[ self->tableNameDepth ] = NULL; }
functions
void _TOML_stringifyText( struct _TOMLStringifyData *self, char *text, int n ) { if ( self->bufferIndex + n + 1 >= self->bufferSize ) { self->buffer = _TOML_increaseBuffer( self->buffer, &self->bufferSize ); }
functions
void _TOML_stringifyTableHeader( struct _TOMLStringifyData *self, TOMLTable *table ) { TOMLBasic *first = TOMLArray_getIndex( table->values, 0 ); if ( !first || first->type == TOML_TABLE || ( first->type == TOML_ARRAY && ((TOMLArray *) first)->memberType == TOML_TABLE ) ) { return; }
functions
void _TOML_stringifyArrayHeader( struct _TOMLStringifyData *self ) { if ( self->bufferIndex != 0 ) { _TOML_stringifyText( self, "\n", 1 ); }
functions
void _TOML_stringifyString( struct _TOMLStringifyData *self, TOMLString *string ) { char *cursor = string->content; while ( cursor != NULL ) { // Scan for escapable character or unicode. char *next = cursor; unsigned int ch = *next; for ( ; !( ch == 0 || ch == '\b' || ch == '\t' || ch == '\f' || ch == '\n' || ch == '\r' || ch == '"' || ch == '/' || ch == '\\' || ch > 0x7f ); next++, ch = *next ) {}
functions
void _TOML_stringifyEntry( struct _TOMLStringifyData *self, TOMLString *key, TOMLBasic *value ) { _TOML_stringifyText( self, key->content, key->size ); _TOML_stringifyText( self, " = ", 3 ); if ( value->type == TOML_STRING ) { _TOML_stringifyText( self, "\"", 1 ); _TOML_stringifyString( self, (TOMLString *) value ); _TOML_stringifyText( self, "\"", 1 ); }
functions
int _TOML_stringify( struct _TOMLStringifyData *self, TOMLRef src ) { // Cast to TOMLBasic to discover type. TOMLBasic *basic = src; // if null if ( src == NULL ) { _TOML_stringifyText( self, "(null)", 6 ); // if table }
functions
else if ( basic->type == TOML_TABLE ) { TOMLTable *table = src; // loop keys for ( int i = 0; i < table->keys->size; ++i ) { TOMLRef key = TOMLArray_getIndex( table->keys, i ); TOMLRef value = TOMLArray_getIndex( table->values, i ); TOMLBasic *basicValue = value; // if value is table, print header, recurse if ( basicValue->type == TOML_TABLE ) { TOMLTable *tableValue = value; _TOML_stringifyPushName( self, key ); _TOML_stringifyTableHeader( self, value ); _TOML_stringify( self, value ); _TOML_stringifyPopName( self ); // if value is array }
functions
else if ( basicValue->type == TOML_ARRAY ) { TOMLArray *array = value; // if value is object array if ( array->memberType == TOML_TABLE ) { // loop indices, print headers, recurse for ( int j = 0; j < array->size; ++j ) { _TOML_stringifyPushName( self, key ); _TOML_stringifyArrayHeader( self ); _TOML_stringify( self, TOMLArray_getIndex( array, j ) ); _TOML_stringifyPopName( self ); }
functions
else if ( basic->type == TOML_ARRAY ) { TOMLArray *array = src; // print array densely _TOML_stringifyText( self, "[", 1 ); for ( int i = 0; i < array->size; ++i ) { _TOML_stringifyText( self, " ", 1 ); TOMLBasic *arrayValue = TOMLArray_getIndex( array, i ); if ( arrayValue->type == TOML_STRING ) { _TOML_stringifyText( self, "\"", 1 ); _TOML_stringifyString( self, (TOMLString *) arrayValue ); _TOML_stringifyText( self, "\"", 1 ); }
functions
else if ( basic->type == TOML_STRING ) { TOMLString *string = src; // print string _TOML_stringifyText( self, string->content, string->size ); // if number }
functions
else if ( basic->type == TOML_BOOLEAN ) { TOMLBoolean *boolean = (TOMLBoolean *) basic; if ( boolean->isTrue ) { _TOML_stringifyText( self, "true", 4 ); }
functions
else if ( basic->type == TOML_DATE ) { TOMLDate *date = (TOMLDate *) basic; char numberBuffer[ 16 ]; int size; size = snprintf( numberBuffer, 15, format, date->part ); \ _TOML_stringifyText( self, numberBuffer, size ); \ _TOML_stringifyText( self, spacer, 1 ) STRINGIFY_DATE_SECTION( "%d", year, "-" ); STRINGIFY_DATE_SECTION( "%0.2d", month, "-" ); STRINGIFY_DATE_SECTION( "%0.2d", day, "T" ); STRINGIFY_DATE_SECTION( "%0.2d", hour, ":" ); STRINGIFY_DATE_SECTION( "%0.2d", minute, ":" ); STRINGIFY_DATE_SECTION( "%0.2d", second, "Z" ); #undef STRINGIFY_DATE_SECTION }
functions
int TOML_stringify( char **buffer, TOMLRef src, TOMLError *error ) { int bufferSize = 0; char *output = _TOML_increaseBuffer( NULL, &bufferSize ); int stackSize = 0; TOMLString **tableNameStack = _TOML_increaseNameStack( NULL, &stackSize ); struct _TOMLStringifyData stringifyData = { error, bufferSize, 0, output, 0, stackSize, tableNameStack }
defines
#define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
functions
void PyErr_Restore(PyObject *type, PyObject *value, PyObject *traceback) { PyThreadState *tstate = PyThreadState_GET(); PyObject *oldtype, *oldvalue, *oldtraceback; /* Save these in locals to safeguard against recursive invocation through Py_XDECREF */ oldtype = tstate->curexc_type; oldvalue = tstate->curexc_value; oldtraceback = tstate->curexc_traceback; tstate->curexc_type = type; tstate->curexc_value = value; tstate->curexc_traceback = traceback; Py_XDECREF(oldtype); Py_XDECREF(oldvalue); Py_XDECREF(oldtraceback); }
functions
void PyErr_SetObject(PyObject *exception, PyObject *value) { Py_XINCREF(exception); Py_XINCREF(value); PyErr_Restore(exception, value, (PyObject *)NULL); }
functions
void PyErr_SetNone(PyObject *exception) { PyErr_SetObject(exception, (PyObject *)NULL); }
functions
void PyErr_SetString(PyObject *exception, const char *string) { PyObject *value = PyString_FromString(string); PyErr_SetObject(exception, value); Py_XDECREF(value); }
functions
int PyErr_GivenExceptionMatches(PyObject *err, PyObject *exc) { if (err == NULL || exc == NULL) { /* maybe caused by "import exceptions" that failed early on */ return 0; }
functions
int PyErr_ExceptionMatches(PyObject *exc) { return PyErr_GivenExceptionMatches(PyErr_Occurred(), exc); }
functions
void PyErr_NormalizeException(PyObject **exc, PyObject **val, PyObject **tb) { PyObject *type = *exc; PyObject *value = *val; PyObject *inclass = NULL; PyObject *initial_tb = NULL; if (type == NULL) { /* There was no exception, so nothing to do. */ return; }
functions
else if (inclass != type) { Py_DECREF(type); type = inclass; Py_INCREF(type); }
functions
void PyErr_Fetch(PyObject **p_type, PyObject **p_value, PyObject **p_traceback) { PyThreadState *tstate = PyThreadState_Get(); *p_type = tstate->curexc_type; *p_value = tstate->curexc_value; *p_traceback = tstate->curexc_traceback; tstate->curexc_type = NULL; tstate->curexc_value = NULL; tstate->curexc_traceback = NULL; }
functions
void PyErr_Clear(void) { PyErr_Restore(NULL, NULL, NULL); }
functions
int PyErr_BadArgument(void) { PyErr_SetString(PyExc_TypeError, "bad argument type for built-in operation"); return 0; }
functions
void _PyErr_BadInternalCall(char *filename, int lineno) { PyErr_Format(PyExc_SystemError, "%s:%d: bad argument to internal function", filename, lineno); }
functions
void PyErr_BadInternalCall(void) { PyErr_Format(PyExc_SystemError, "bad argument to internal function"); }