int main(int argc, char* argv[]) { if (argc > 1) { if ( 0 == strcmp("h", argv[1])) { say_hello(); } else { say_bye(); } return 0; } say_hello(); say_bye(); return 0; }
void handle_request(void) { void *allocs[100] = {0}; uint32_t alloc_idx; sendstr(" **** WELCOME TO THE HEAP SIMULATOR 2001! ****\n\n"); while (1) { sendstr("What would you like to do?\n"); sendstr(" 1) Allocate memory\n"); sendstr(" 2) Free memory\n"); sendstr(" 3) Read some data\n"); sendstr(" 4) Exit\n\n"); int cmd = readint(); uint16_t id; switch (cmd) { case 1: for (alloc_idx = 0; alloc_idx < sizeof(allocs) && allocs[alloc_idx] != NULL; ++alloc_idx) ; if (alloc_idx >= sizeof(allocs)) { sendstr("Run out of space, free something first!\n"); } else { sendstr("Ok, how much memory do you want (in bytes)?\n"); uint16_t bytes = readint(); allocs[alloc_idx] = (void *)alloc(bytes); sendstr(tprintf("Allocated with ID = %d\n", alloc_idx)); } dump_heap(); break; case 2: sendstr("Please enter the ID of the alloc to free\n"); id = readint(); if (id < sizeof(allocs) && allocs[id] != NULL) { dealloc(allocs[id]); allocs[id] = NULL; } else { sendstr("Alloc not found\n"); } dump_heap(); break; case 3: sendstr("Please enter the ID of the alloc where to read data\n"); id = readint(); if (id < sizeof(allocs) && allocs[id] != NULL) { sendstr("Ready! Send the data\n"); recvline(client_fd, allocs[id], 0x100); } else { sendstr("Alloc not found\n"); } dump_heap(); break; case 4: say_bye(); exit(0); break; default: sendstr("What!?\n"); }; } }
int main(int argc, char *argv[]) { printf("-- Application --\n"); printf(" - Name: \"%s\"\n", libmod_application.stub.name); printf(" - Description: \"%s\"\n", libmod_application.stub.description); printf(" - Version: %i.%i.%i build %i\n", libmod_application.stub.version.major, libmod_application.stub.version.minor, libmod_application.stub.version.revision, libmod_application.stub.version.build); printf("-- Exports --\n"); printf(" - %li export(s):\n", libmod_application.stub.exports.count); for(int i = 0; i < libmod_application.stub.exports.count; i++) { printf(" - %s -> %p\n", libmod_application.stub.exports.functions[i].name, libmod_application.stub.exports.functions[i].address); } printf("-- Module --\n"); const char *module_name = "./module.lmm"; libmod_module_t *module = libmod_module_load(&libmod_application, module_name); if(module == NULL) { printf(" - (Error) %s: %s.\n", libmod_error_string(libmod_error_number()), libmod_error_details()); return libmod_exit(libmod_error_number()); } else { printf(" - Name: \"%s\"\n", module->stub.name); printf(" - Description: \"%s\"\n", module->stub.description); printf(" - Version: %i.%i.%i build %i\n", module->stub.version.major, libmod_application.stub.version.minor, libmod_application.stub.version.revision, libmod_application.stub.version.build); printf("-- Exports --\n"); printf(" - %li export(s):\n", module->stub.exports.count); for(int i = 0; i < module->stub.exports.count; i++) { printf(" - %s -> %p\n", module->stub.exports.functions[i].name, libmod_application.stub.exports.functions[i].address); } } say_hi = libmod_function_fromname(&module->stub, "say_hi"); // Get the libmod_modtest function inside it if(say_hi == NULL) { printf(" - (Error) %s: %s.\n", libmod_error_string(libmod_error_number()), libmod_error_details()); libmod_module_unload(&libmod_application, module); return libmod_exit(libmod_error_number()); } printf("-- Function test --\n"); printf(" - say_hi(); say_bye();: "); say_hi(); say_bye(); if(libmod_module_unload(&libmod_application, module) != ENOERROR) { // Unload the module printf(" - (Error) %s: %s.\n", libmod_error_string(libmod_error_number()), libmod_error_details()); return libmod_exit(libmod_error_number()); } return ENOERROR; }
int main(){ const char* name="Alfa"; say_hi(name); say_bye(name); return 0; }