int requestURL(const char *url, unsigned char **p_data, unsigned int *p_len) { char *name; size_t len; url = strrchr(url, '/'); if (url == NULL) { LOG(LERROR, "URL is malformed.\n"); return -1; } url++; // get request name len = strcspn(url, "?"); if (asprintf(&name, "%s/%.*s", g_paths.urlPath, (int)len, url) < 0) { LOG(LERROR, "Out of memory\n"); return -1; } int ret = readFileToBuffer(name, 0, p_data, p_len); LOG(LDEBUG, "Reading of %s returned %d.\n", name, ret); free(name); return ret; }
int main(int argc, char ** args) { char *source; int count; long elapsed; struct timespec timer; int i; for (i = 1; i < argc; ++i) { timer_start(&timer); long filesize = readFileToBuffer(args[i], &source); elapsed = timer_end(timer); printf("%lu bytes of file '%s' loaded in %.2fms\n", filesize, args[i], elapsed/1000000.0); timer_start(&timer); count = kaesvesCountAbcabc(source); elapsed = timer_end(timer); printf("kaesve reports %d matches in %.2fms\n", count, elapsed/1000000.0); timer_start(&timer); count = mytherinsCountAbcabc(source); elapsed = timer_end(timer); printf("mytherin reports %d matches in %.2fms\n", count, elapsed/1000000.0); printf("\n"); free(source); } }
void codecs::on_readBtn_clicked() { QFileDialog *dialog = new QFileDialog(); dialog->setDirectory(curDir); dialog->setWindowTitle("Open *any* file to decode if possible"); readFileToBuffer(dialog->getOpenFileName()); }
void codecs::dropEvent(QDropEvent *event) { QList<QUrl> fList = event->mimeData()->urls(); if(fList.isEmpty()) return; else if(fList.size() > 1){ QMessageBox::information(this, "Multi File Dropped", QString("Will Convert Only One File In this Session\n%1") .arg(fList.first().toLocalFile()), QMessageBox::Ok); } QString fName = fList.first().toLocalFile(); readFileToBuffer(fName); }
int main(int argc, char **argv) { CURL *curlHandle; CURLcode res; struct curl_slist *headerList = NULL; char *urlString = "http://192.168.201.20:8080/wm/core/controller/switches/json"; //curl_global_init(CURL_GLOBAL_ALL); //curlHandle = curl_easy_init(); //init the curl session struct MemoryStruct httpPostBody; httpPostBody.data = readFileToBuffer(argv[1]); httpPostBody.size = strlen(httpPostBody.data); //nie potrzeba nulla na koncu dawac httpPostBody.bytesCopied = 0; httpPostBody.bytesRemaining = httpPostBody.size; struct MemoryStruct httpResponseBody; struct MemoryStruct httpResponseHeaders; httpResponseBody.data = malloc(1); httpResponseBody.size = 0; httpResponseHeaders.data = malloc(1); httpResponseHeaders.size = 0; httpPost(NULL, urlString, &httpPostBody, &httpResponseBody, &httpResponseHeaders); printf("Wczytane body: \n%s\n", httpResponseBody.data); printf("Wczytane hedery: \n%s\n", httpResponseHeaders.data); free(httpPostBody.data); if (httpResponseBody.data) free(httpResponseBody.data); if (httpResponseHeaders.data) free(httpResponseHeaders.data); //curl_global_cleanup(); return 0; }
/*-------------------- readFile --------------------*/ File_t readFile ( ParameterSpecification_t fileSpecifier, /* in */ const char * filename /* in */ ) { File_t returnValue; FILE * filePointer; long fileLength; if( FileOpened == openFileForReading( filename, &filePointer ) ) { if( Success == getFileLength( filePointer, &fileLength ) ) { void * ptr; /* * Allocate one byte more if a newline must be added */ if( Success == allocateBuffer( fileLength + 1 , &ptr ) ) { char * buffer = ( char * )ptr; if( Success == readFileToBuffer( filePointer, fileLength, &buffer ) ) { if ( FALSE == queryParameter( IgnoreEOF ) ) { char * eof = (buffer + fileLength - 1); if ( *eof != '\n' ) { *( eof + 1 ) = '\n'; fileLength++; } } addToWatchdog( fileLength ); associateBuffer( fileSpecifier, fileLength, &buffer ); returnValue = FileOperationsSuccessful; } else { freeBuffer( &buffer ); returnValue = FileOperationsFailed; } } else { returnValue = FileOperationsFailed; } } else { returnValue = FileOperationsFailed; } closeFile( filePointer ); } else { returnValue = FileOperationsFailed; } return( returnValue ); }
Shader::Shader(const string& filename, ShaderType type) { filename_ = jtil::string_util::ToWideString(filename); compiled_ = false; // Read in the raw shader source shader_source_ = readFileToBuffer(filename); // Append the include code: We need to scan through the code looking for // lines that have "#include" and replace them with the correct text. // This could be much more efficient, but is fast enough for just startup int include_pos = findInclude(shader_source_); while (include_pos != -1) { string f_include = extractIncludeFilename(shader_source_, include_pos); GLchar* inc_source = readFileToBuffer(f_include); shader_source_ = insertIncludeSource(shader_source_, inc_source, include_pos); free(inc_source); // There might be more, so find the next one include_pos = findInclude(shader_source_); } // Assign a shader handle switch (type) { case VERTEX_SHADER: shader_ = GLState::glsCreateShader(GL_VERTEX_SHADER); break; case FRAGMENT_SHADER: shader_ = GLState::glsCreateShader(GL_FRAGMENT_SHADER); break; default: throw std::runtime_error("Shader::Shader() - unrecognized shader type!"); } // Send the shader source code to OpenGL // Note that the source code is NULL character terminated. // GL will automatically detect that therefore the length info can be 0 // in this case (the last parameter) GLState::glsShaderSource(shader_, 1, const_cast<const GLchar**>(&shader_source_), 0); // Compile the shader GLState::glsCompileShader(shader_); // Check that everything compiled OK int is_compiled; GLState::glsGetShaderiv(shader_, GL_COMPILE_STATUS, &is_compiled); if(is_compiled == 0) { int info_length; GLState::glsGetShaderiv(shader_, GL_INFO_LOG_LENGTH, &info_length); // The maxLength includes the NULL character char* shader_info_log; shader_info_log = new char[info_length]; GLState::glsGetShaderInfoLog(shader_, info_length, &info_length, shader_info_log); ERROR_CHECK; wstring err_log = jtil::string_util::ToWideString(shader_info_log); delete[] shader_info_log; std::cout << std::endl; std::cout << "Cannot compile the following shader code: "; std::cout << jtil::string_util::ToNarrowString(filename_).c_str() << std::endl; std::cout << " --> Compilation error: " << std::endl; std::cout << jtil::string_util::ToNarrowString(err_log).c_str(); std::cout << " --> For the code:" << std::endl; std::cout << "*********************************************************"; std::cout << std::endl; printToStdOut(); std::cout << "*********************************************************"; std::cout << std::endl; throw std::runtime_error(string("Shader::Shader() - ERROR compiling") + string(" shader from file: ") + jtil::string_util::ToNarrowString(filename_) + string(": ") + jtil::string_util::ToNarrowString(err_log)); } else { compiled_ = true; } }