void handler(void *pSock){ sock rsock = *((sock *)pSock); int int1, int2; char sBuf[BUFSIZE]; char rBuf[BUFSIZE]; memset(rBuf, '\0', BUFSIZE); memset(sBuf, '\0', BUFSIZE); signal(SIGFPE, sig_handler); signal(SIGPIPE, SIG_IGN); signal(SIGSEGV, seg_handler); if (!rprintf(rsock, "Enter a number: ")) goto Cleanup; if (!rgets(rsock, rBuf)) goto Cleanup; int1 = atoi(rBuf); if (!rprintf(rsock, "Enter another number: ")) goto Cleanup; int1 = atoi(rBuf); if (!rgets(rsock, rBuf)) goto Cleanup; int2 = atoi(rBuf); pthread_mutex_lock(&tmutex); gsock = rsock; int ans = int1 / int2; pthread_mutex_unlock(&tmutex); if (!rprintf(rsock, "%d divided by %d equals: %d\n", int1, int2, ans)) goto Cleanup; Cleanup: close(rsock); pthread_exit(NULL); }
struct ast* eval_native_method(struct ast* m){ if (m != NULL){ char* method_name; if (m->node_type == N_METHOD_CALL_2) { method_name = strdup(((struct method_call_node*)m)->method_name); } else if (m->node_type == N_IDENTIFIER) { method_name = strdup(((struct identifier_node*)m)->name); }; if (!strcmp(method_name, PUTS)) { return rputs(m); } else if (!strcmp(method_name, GETS)) { return rgets(); }; }; return new_nil_node(); };