void obtenerConfiguracion(char* nombre_archivo) { t_config* config; configuracion = (t_Datos_configuracion*) malloc(sizeof(t_Datos_configuracion)); char* path = file_combine(PATH_CONFIG, nombre_archivo); config = config_create(path); if (config_has_property(config, "IP_MARTA")) { configuracion->ip_marta = strdup(config_get_string_value(config, "IP_MARTA")); } else { log_error_consola("El archivo de configuracion %s debe tener un IP_MARTA", path); exit(1); } if (config_has_property(config, "REDUCE")) { configuracion->reduce = read_whole_file(config_get_string_value(config, "REDUCE")); configuracion->tamanio_reduce = file_get_size(config_get_string_value(config, "REDUCE")); } else { log_error_consola("El archivo de configuracion %s debe tener un REDUCE", path); exit(1); } if (config_has_property(config, "MAPPER")) { configuracion->mapper = read_whole_file(config_get_string_value(config, "MAPPER")); configuracion->tamanio_mapper = file_get_size(config_get_string_value(config, "MAPPER")); } else { log_error_consola("El archivo de configuracion %s debe tener un MAPPER", path); exit(1); } if (config_has_property(config, "PUERTO_MARTA")) { configuracion->puerto_marta = config_get_int_value(config, "PUERTO_MARTA"); } else { log_error_consola("El archivo de configuracion %s debe tener un PUERTO_MARTA", path); exit(1); } if (config_has_property(config, "COMBINER")) { configuracion->combiner = !strcmp(config_get_string_value(config, "COMBINER"), "SI") ? 1 : 0; } else { log_error_consola("El archivo de configuracion %s debe tener un COMBINER", path); exit(1); } if (config_has_property(config, "RESULTADO")) { configuracion->resultado = strdup(config_get_string_value(config, "RESULTADO")); } else { log_error_consola("El archivo de configuracion %s debe tener un RESULTADO", path); exit(1); } if (config_has_property(config, "ARCHIVOS")) { configuracion->archivos = strdup(config_get_string_value(config, "ARCHIVOS")); } else { log_error_consola("El archivo de configuracion %s debe tener un ARCHIVOS", path); exit(1); } log_info_consola("El archivo de configuracion %s fue cargado con exito", path); config_destroy(config); }
void foo() { char buf[128] = {0}; struct file *f = file_open("/tmp/lsusb", F_RDONLY); file_read(f, buf, sizeof(buf)); printf("buf =%s", buf); printf("len=%zu\n", file_get_size("/tmp/lsusb")); }
static int register_aio_file(const char *path) { struct ns_entry *entry; int flags, fd; uint64_t size; uint32_t blklen; if (g_rw_percentage == 100) { flags = O_RDONLY; } else { flags = O_RDWR; } flags |= O_DIRECT; fd = open(path, flags); if (fd < 0) { fprintf(stderr, "Could not open AIO device %s: %s\n", path, strerror(errno)); return -1; } size = file_get_size(fd); if (size == 0) { fprintf(stderr, "Could not determine size of AIO device %s\n", path); close(fd); return -1; } blklen = dev_get_blocklen(fd); if (blklen == 0) { fprintf(stderr, "Could not determine block size of AIO device %s\n", path); close(fd); return -1; } entry = malloc(sizeof(struct ns_entry)); if (entry == NULL) { close(fd); perror("aio ns_entry malloc"); return -1; } entry->type = ENTRY_TYPE_AIO_FILE; entry->u.aio.fd = fd; entry->size_in_ios = size / g_io_size_bytes; entry->io_size_blocks = g_io_size_bytes / blklen; snprintf(entry->name, sizeof(entry->name), "%s", path); g_num_namespaces++; entry->next = g_namespaces; g_namespaces = entry; return 0; }
ssize_t ft5406_read_firmware_data1(const char *cfgpath, char *buff, size_t size) { ssize_t readlen; char *text_buff, *p, *p_end; char *buff_bak, *buff_end; u8 value; readlen = file_get_size(cfgpath); if (readlen < 0) { pr_red_info("file_get_size %s", cfgpath); return readlen; } text_buff = malloc(readlen); if (text_buff == NULL) { pr_red_info("malloc"); return -ENOMEM; } readlen = file_read(cfgpath, text_buff, readlen); if (readlen < 0) { pr_red_info("file_read %s", cfgpath); free(text_buff); return readlen; } buff_bak = buff; buff_end = buff + size; for (p = text_buff, p_end = p + readlen; p < p_end; p++) { if (*p != 'x' && *p != 'X') { continue; } for (value = 0, p++; p < p_end; p++) { int temp; temp = char2value(*p); if (temp > 15 || temp < 0) { break; } value = value << 4 | temp; } if (buff < buff_end) { *buff++ = value; } else { break; } } free(text_buff); return buff - buff_bak; }
BU_UINT8 file_get_list(const char* path, file_info_t* info_arr, BU_UINT32 arrNum) { DIR *dp = NULL; struct dirent *dirp = NULL; struct stat statbuf; char filePath[FILE_MAX_NAME_LEN] = {0}; BU_UINT32 i = 0; if ((dp = opendir (path)) == NULL) { E_LOG("opendir file\n"); return 0; } while ((dirp = readdir(dp)) != NULL) { /*ignore hidden file*/ if ((strcmp (dirp->d_name, ".") == 0 || strcmp (dirp->d_name, "..") == 0)){ continue; } bzero(filePath, sizeof (filePath)); sprintf (filePath, "%s/%s", path, dirp->d_name); /* get file profile */ memcpy(info_arr[i].name, dirp->d_name, strlen(dirp->d_name)); if (dirp->d_type == 4) { info_arr[i].type = FTYPE_DIR; info_arr[i].size = 1; } else if (dirp->d_type == 8) { info_arr[i].type = FTYPE_NORMAL; info_arr[i].size = file_get_size(filePath); } else { info_arr[i].type = FTYPE_UNKNOW; info_arr[i].size = 0; } if (lstat (filePath, &statbuf) != 0) { E_LOG("lstat2 file error: %s\n", strerror (errno)); memset(&info_arr[i], 0, sizeof(file_info_t)); continue; } info_arr[i].modifi_time = statbuf.st_mtime; i++; } return BU_OK; }
int sprites_load(sprites_t** psprites, const char* fname) { struct file_t* file = NULL; if (file_open_reader(&file, fname, FILE_SIGNATURE, FILE_VERSION) != 0) { return -1; } uint32_t data_size = file_get_size(file); char* data = malloc(data_size); file_read(file, data, data_size); file_close(file); sprites_t* sprites = (sprites_t*)data; sprites->sprites = (sprite_t*)(data + (uintptr_t)sprites->sprites); LOGI("Sprites metadata has %d sprites", sprites->nsprites); uint32_t i = 0; uint32_t j = 0; uint32_t k = 0; sprite_t* sprite = &sprites->sprites[0]; for (; i < sprites->nsprites; ++i, ++sprite) { LOGI("Sprite '%s' has %d tracks and flags %d", sprite->name, sprite->animation.ntracks, sprite->animation.flags); sprite->sprite_names = (sprite_id_t*)(data + (uintptr_t)sprite->sprite_names); sprite->animation.tracks = (animation_track_t*)(data + (uintptr_t)sprite->animation.tracks); animation_track_t* track = &sprite->animation.tracks[0]; for (j = 0; j < sprite->animation.ntracks; ++j, ++track) { LOGI(" Track #%d [type %d interpolation %d] has %d frames [offset %p]", j, track->type, track->interpolation, track->nframes, track->frames); track->frames = (animation_frame_t*)(data + (uintptr_t)track->frames); const animation_frame_t* frame = &track->frames[0]; for (k = 0; k < track->nframes; ++k, ++frame) { LOGI(" Frame #%d timestamp %d", k, frame->timestamp); } } } qsort(&sprites->sprites[0], sprites->nsprites, sizeof(sprite_t), cmp_sprite_by_name); (*psprites) = sprites; return 0; }
/* * devuelve un puntero con el archivo mapeado */ void* getFileContent(char* filename) { log_info(_log, "Inicio getFileContent(%s)", filename); void* content = NULL; //creo el espacio para almacenar el archivo char* path = file_combine(config_get_string_value(_config, CONFIG_DIR_TEMP), filename); content = malloc(file_get_size(path)); content = file_get_mapped(path); free(path); log_info(_log, "Fin getFileContent(%s)", filename); return content; }
int main(int ac, char** av) { file_context_t fc = FILE_STATIC_INITIALIZER; pcm_buf_t* pcm_buf = NULL; mod_context_t mc; if (file_open(&fc, ac > 1 ? av[1] : "../data/alban.mod") == -1) { printf("failed opening file\n"); goto on_error; } if (mod_init(&mc, file_get_data(&fc), file_get_size(&fc)) == -1) { printf("failed mod_init\n"); goto on_error; } pcm_alloc_buf(&pcm_buf, 48000); { FILE *f=fopen("output.raw","wb"); unsigned int i; for (i = 0; i < 100; ++i) { mod_fetch(&mc, pcm_get_buf_data(pcm_buf), pcm_get_buf_count(pcm_buf)); #if 0 write(1, pcm_get_buf_data(pcm_buf), pcm_get_buf_size(pcm_buf)); #else fwrite(pcm_get_buf_data(pcm_buf),1,pcm_get_buf_size(pcm_buf),f); #endif } fclose(f); } on_error: if (pcm_buf != NULL) pcm_free_buf(pcm_buf); file_close(&fc); return 0; }
byte file_open(file *io, char *path, char *mode){ //return error int i; #if NULL_ARG_CHECK if (mode == NULL){ fprintf(stderr, "[error] file_open: mode == NULL\n"); return -1; } #endif if (io->fp != NULL){ file_close(io); } file_reset(io); io->fp = fopen(path, mode); if (io->fp == NULL){ if (mode[0] != 'r' && mode[0] != 'w' && mode[0] != 'a'){ fprintf(stderr, "[error] file_open: mode not in (r, w, a) [%s, %s]\n", path, mode); return -2; } else{ fprintf(stderr, "[error] file_open: file not exist [%s, %s]\n", path, mode); return -3; } } for (i=0; i<3; i++){ if (mode[i] == '\x00'){ break; } else if (mode[i] == 'r'){ io->size = file_get_size(path); io->mode_read = 1; } else if (mode[i] == 'w'){ io->mode_write = 1; } else if (mode[i] == 'a' || mode[i] == '+'){ io->mode_add = 1; } } return 0; }
/* if the target key has not been found, the method will return NULL */ int conf_get_value_by_key(char *value, char *file_path, char* target_key) { char *conf_opt; char key[TOKEN_NAME_MAX_LEN]; char *buffer; CONFIG *config; int i; int file_size; Assert(value != NULL); file_size = file_get_size(file_path); buffer = (char *)MEMALLOCHEAP(file_size); file_read(file_path, buffer, file_size); config = conf_build(buffer, LINE_SEPARATOR); for(i=0; i<config->conf_opt_size; i++) { conf_opt = config->conf_opt_infor[i].conf_value; Assert(STRLEN(conf_opt) != 0); MEMSET(key, TOKEN_NAME_MAX_LEN); conf_get_key(key, conf_opt); if(match(key, target_key)) { conf_get_value(value, conf_opt); break; } } conf_destroy(config); trim(value, ' '); MEMFREEHEAP(buffer); return TRUE; }
int SAL_GetSize( STORAGE_HANDLE aHandle ) { int sz; Ptr_Storage_Desc ptr_storage; sz = -1; assert( IS_HANDLE_VALID( aHandle ) ); ptr_storage = *aHandle; switch( ptr_storage->backend_type ) { case NAND_TYPE: sz = ptr_storage->backend_info.nand.size_in_bytes; break; case FILE_TYPE: sz = file_get_size( ptr_storage->backend_info.file.pFileName ); break; default: break; } return sz; }
static void cargarCodigo() { int fd = open("/home/utnso/tp-2015-2c-tpso/CPU/corto.cod", O_RDONLY); if (fd == -1) { perror("Error al abrir el archivo"); exit(EXIT_FAILURE); } int tamanio = file_get_size("/home/utnso/tp-2015-2c-tpso/CPU/corto.cod"); char buffer[tamanio]; int numbytes = read(fd, buffer, sizeof(buffer)); buffer[tamanio] = '\0'; if (numbytes == -1) { perror("fallo en read"); exit(EXIT_FAILURE); } char** sinEnter; sinEnter = string_split(buffer, "\n"); int i = 0; char* sin_enter = string_new(); while (sinEnter[i] != NULL) { string_append(&sin_enter, sinEnter[i]); i++; } CU_ASSERT_STRING_EQUAL(sin_enter, "iniciar 2;leer 0;leer 1;finalizar;"); }
byte parser_parse_file( Parser* _ptr_parser,char* _path_to_file ){ _ptr_parser->file_handler_ = new_file( _path_to_file ); string_set( _ptr_parser->path_to_file_,_path_to_file ); char * buffer_file = file_get_buffer( _ptr_parser->file_handler_ ); unsigned int file_size = file_get_size( _ptr_parser->file_handler_ ), i = 0, j = 0, c = 0, num_functions = 0; while( i<file_size ){ if( PARSER_ALL_TOKENS( buffer_file ) ){ if( i-j == 0 ){ i+=1; j++; continue; } char* strcontainer = calloc( i-j,1 ); memcpy( strcontainer,&buffer_file[j],i-j ); if( buffer_file[i] == PARSER_TOKEN_COLON && strcmp( strcontainer,PARSER_TOKEN_MAIN ) ) svector_push_text( _ptr_parser->functions_names_table_, strcontainer ); c++; svector_push_text( _ptr_parser->parse_code_,strcontainer ); free( strcontainer ); i+=1; j=i; continue; } i++; } #ifdef PARSER_DEBUGMODE svector_dump( _ptr_parser->functions_names_table_ ); #endif return PARSER_NOERROR; }
int main(int argc, char **argv) { unsigned int i; png_byte **row_pointers; unsigned int filesize; png_infop info_ptr; png_structp png_ptr; if(argc!=3) usage(argv[0]); rawfile = fopen(argv[1], "rb"); if(!rawfile) usage(argv[0]); filesize = file_get_size(rawfile); side_size = raw_get_side(filesize); if(side_size == 0) usage(argv[0]); raw_buffer = malloc(filesize); if( !raw_buffer ) { fprintf(stderr, "Not enough memory\n"); fclose(rawfile); exit(EXIT_FAILURE); } if(fread(raw_buffer, sizeof(char), filesize, rawfile) != filesize) { fprintf(stderr, "Raw file reading error\n"); fclose(rawfile); free(raw_buffer); exit(EXIT_FAILURE); } fclose(rawfile); /*Create png file*/ pngfile = fopen(argv[2], "wb"); if(!pngfile) { fprintf(stderr, "Can't open %s for writting\n", argv[2]); free(raw_buffer); exit(EXIT_FAILURE); } png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_ptr) { fprintf(stderr, "Can't create png file\n"); free(raw_buffer); fclose(pngfile); exit(EXIT_FAILURE); } info_ptr = png_create_info_struct(png_ptr); if (!png_ptr) { png_destroy_write_struct(&png_ptr, (png_infopp)NULL); fprintf(stderr, "Can't create png file\n"); free(raw_buffer); fclose(pngfile); exit(EXIT_FAILURE); } png_init_io(png_ptr, pngfile); png_set_IHDR(png_ptr, info_ptr, side_size, side_size, 8, PNG_COLOR_TYPE_GRAY, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); row_pointers = malloc(sizeof(png_byte *)*side_size); if( !row_pointers ) { png_destroy_write_struct(&png_ptr, &info_ptr); fprintf(stderr, "Not enough memory\n"); free(raw_buffer); fclose(pngfile); exit(EXIT_FAILURE); } png_write_info (png_ptr, info_ptr); for(i = 0; i < side_size; i++) row_pointers[i] = raw_buffer+i*side_size; png_write_image(png_ptr, row_pointers); png_write_end(png_ptr, NULL); png_destroy_write_struct(&png_ptr, &info_ptr); fclose(pngfile); exit(EXIT_SUCCESS); }
static int lua_to_peer_data(struct lua_State *L, enum lua_place from, const char *name, uint32_t socket, struct peer_data *peer_data, size_t *cl, struct hash_set *hs) { uint32_t hdr_len, hdr_beg, content_len, content_beg; char hdr_file[256], content_file[256]; int pop; if ((pop = lua_getfrom(L, from, name)) < 0) return -1; if (!lua_istable(L, -1)) return -1; if (lua_getfrom(L, TABLE, "header") < 0) return -1; if (lua_to_int(L, TABLE, "len", &hdr_len) < 0) return -1; if (lua_to_int(L, TABLE, "beg", &hdr_beg) < 0) return -1; if (lua_to_string(L, TABLE, "file_name", hdr_file, sizeof(hdr_file)) < 0) return -1; lua_pop(L, 1); if (lua_getfrom(L, TABLE, "content") < 0) return -1; if (lua_to_int(L, TABLE, "len", &content_len) < 0) return -1; if (lua_to_int(L, TABLE, "beg", &content_beg) < 0) return -1; if (lua_to_string(L, TABLE, "file_name", content_file, sizeof(content_file)) < 0) return -1; lua_pop(L, 1); if (hdr_len == UINT32_MAX) { long ret = file_get_size(hdr_file); if (ret < 0) { plog_err("%s", file_get_error()); return -1; } hdr_len = ret - hdr_beg; } if (content_len == UINT32_MAX) { long ret = file_get_size(content_file); if (ret < 0) { plog_err("%s", file_get_error()); return -1; } content_len = ret - content_beg; } *cl = content_len; peer_data->hdr_len = hdr_len; if (file_read_cached(hdr_file, &peer_data->hdr, hdr_beg, hdr_len, socket, hs)) return -1; if (file_read_cached(content_file, &peer_data->content, content_beg, content_len, socket, hs)) return -1; lua_pop(L, pop); return 0; }
DWORD CFileDownloader::Download( LPCTSTR lpszURL, LPCTSTR lpszFilename, LPCTSTR lpszRefererUrl, LPVOID pUserData, BOOL bUseCache, BOOL bUseProxyConfig ) { m_Stopped = FALSE; if(!SplitDownloadUrl( lpszURL, m_strHostname, m_strHostPath, m_strHostFilename )) return FALSE; m_pUserData = pUserData; m_strDownloadURL = lpszURL; m_strDownloadFile = lpszFilename; // Check the tmp file m_strDownloadFileTemp = m_strDownloadFile + _T(".tmp"); m_strDownloadFileInfo = m_strDownloadFile + _T(".nfo"); // Check if file exists if( bUseCache && IsFileExist(m_strDownloadFile) ) { return TRUE; } else if(!bUseCache) { DeleteFile(m_strDownloadFileTemp); DeleteFile(m_strDownloadFileInfo); DeleteFile(m_strDownloadFile); } CPubConfig::T_ProxySetting proxyconfig; CPubConfig pubconfig; pubconfig.LoadProxyConfig(proxyconfig); SetProxySetting(proxyconfig); INT64 lContentSize = 0; INT64 lFileSize = 0; if( IsFileExist(m_strDownloadFileTemp) && IsFileExist(m_strDownloadFileInfo) ) { CString strLastModified; BOOL notModified = FALSE; if( file_get_contents(m_strDownloadFileInfo, strLastModified) ) { LPCTSTR lpszLengthTag = _T("; length="); LPCTSTR pszLen = _tcsstr(strLastModified, lpszLengthTag); if(pszLen) { pszLen+= _tcslen(lpszLengthTag); lContentSize = _ttoi64(pszLen); } // 检查文件是否完全下载完成了 lFileSize = file_get_size( m_strDownloadFileTemp ); if(lFileSize>0 && lFileSize==lContentSize) { MoveFile(m_strDownloadFileTemp, m_strDownloadFile); DeleteFile(m_strDownloadFileInfo); return TRUE; } if( _CheckIfModifiedSince(lpszURL, strLastModified, bUseProxyConfig, notModified) && notModified ) { } else { lFileSize = 0; } } } // 如果文件已经过期, 或者文件的信息文件不存在, 都删除旧下载临时文件 if(lFileSize==0) { DeleteFile(m_strDownloadFileTemp); DeleteFile(m_strDownloadFileInfo); } // Prepare file _CloseFileHandler(); m_hFile = CreateFile(m_strDownloadFileTemp, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if( m_hFile==INVALID_HANDLE_VALUE ) return FALSE; SetFilePointer( m_hFile, lFileSize, 0, FILE_BEGIN ); if(m_pBuffer==NULL) m_pBuffer = new BYTE[HTTP_BUFFER_SIZE]; INT nRetry = HTTP_DEFAULT_RETYR; INT nRetried = 0; do { INT iRet = _DownloadFileFrom(lFileSize, lContentSize, bUseProxyConfig); DEBUG_TRACE(_T("FD:_DownloadFileFrom %I64d/%I64d LastError:%d Ret:%d"), lFileSize, lContentSize, GetLastError(), iRet); _Cleanup(); if(iRet>0) { // 考虑socket 被主动关闭 if(lFileSize>=lContentSize) break; nRetry = HTTP_DEFAULT_RETYR; } else if(iRet==0) { --nRetry; } else if(iRet==-1) { // 文件长度不匹配! 需要删了文件, 然后重新下载 _CloseFileHandler(); DeleteFile(m_strDownloadFileTemp); DeleteFile(m_strDownloadFileInfo); lFileSize = lContentSize = 0; m_hFile = CreateFile(m_strDownloadFileTemp, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if( m_hFile==INVALID_HANDLE_VALUE ) break; --nRetry; } else if(iRet==-2) { // 写入文件失败, 直接返回 break; } else { ATLASSERT(FALSE); break; } ++ nRetried; } while (!m_Stopped && nRetry>0 && nRetried<HTTP_DEFAULT_MAXRETYR); _CloseFileHandler(); BOOL bFileDone = FALSE; if(lContentSize==0) { // 163.com 等页面 if(lFileSize==0) { DeleteFile(m_strDownloadFileTemp); } else if(!m_Stopped) { bFileDone = TRUE; } } else { bFileDone = lFileSize>=lContentSize; } if(bFileDone) { MoveFile(m_strDownloadFileTemp, m_strDownloadFile); DeleteFile(m_strDownloadFileInfo); } BOOL bRet = PathFileExists(m_strDownloadFile); _FireFileDownloaderEvent(bRet ? IFileDownloaderObserver::DOWNLOAD_COMPLETE : IFileDownloaderObserver::DOWNLOAD_ERROR); return bRet; }
int main(int argc, char *argv[]) { if (argc < 2) { printf(usage, argv[0]); return -1; } bool fixup = false; for (int i = 1; i < argc; ++i) { if (strcmp("--fixup", argv[i]) == 0) fixup = true; } int fd = open(argv[1], O_RDWR); BAIL_IF(fd == -1); void * addr = mmap(NULL, file_get_size(fd), PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0); BAIL_IF(addr == MAP_FAILED); activite_img_t * img = addr; // In all images encountered so far, there were exactly two separate images for (int i = 0; i < 2; ++i) { uint32_t img_crc = crc32(((uint8_t *)addr) + img->images[i].img.offset, img->images[i].img.len); if (img->images[i].img.checksum == img_crc) { switch((IMG_IDENTIFIER)img->images[i].identifier) { case FIRMWARE: puts("Verified firmware checksum"); break; case BOOTLOADER: puts("Verified bootloader checksum"); break; } } else { if (fixup) { img->images[i].img.checksum = img_crc; puts("Recalculated checksum"); } else { puts("One checksum invalid. Did not fix"); } } } const uint32_t header_crc = crc32(img, sizeof(activite_img_t) - sizeof(uint32_t)); if (img->table_checksum == header_crc) { puts("Header checksum verified"); } else { if (fixup) { img->table_checksum = header_crc; puts("Recalculated header checksum"); } else { puts("Header checksum invalid. Did not fix."); } } munmap(addr, file_get_size(fd)); close(fd); return EXIT_SUCCESS; }
/******************************** * EntityCompiler_PawnScript * compiles entity file @ string_inputfile - returns XML error handling */ gchar * EntityCompiler_PawnScript( gchar * input_file, gchar * temporary_filepath ) { GError * err = NULL; gint exit_status; gchar * entity_file = NULL, * compiled_entity_file = NULL; gchar * working_directory = NULL; gchar * full_output_directory = NULL; gchar * args[6] = { NULL, NULL, NULL, NULL, NULL, NULL }; gchar * output = NULL; gchar * output_error = NULL; full_output_directory = g_build_path( "/", AL_ProjectPath(), "c", g_path_get_dirname(input_file), NULL); g_mkdir_with_parents( full_output_directory, 0755 ); #ifdef apple working_directory = Meg_Directory(); #endif args[0] = g_build_filename( Meg_Directory(), PAWN_COMPILER, NULL ); args[1] = g_strconcat( AL_ProjectPath(), input_file, NULL ); args[2] = g_strdup( "--xmloutput"); args[3] = g_strconcat( "--project=", AL_ProjectPath(), NULL ); if ( temporary_filepath ) args[4] = g_strconcat( "--temporary=", temporary_filepath, NULL ); else args[4] = g_strdup( "--notemporary" ); if ( !g_spawn_sync( working_directory, //working_directory args, //gchar **argv, NULL, //gchar **envp, G_SPAWN_SEARCH_PATH, //GSpawnFlags flags, NULL, //GSpawnChildSetupFunc child_setup, NULL, //gpointer user_data, &output, //gchar **standard_output, &output_error, //gchar **standard_error, &exit_status, //gint *exit_status, &err //GError **error )) { output = g_strdup_printf("<results><fatalerror message=\"%s\" file=\"%s\" /></results>", g_markup_escape_text(err->message, -1), args[0] ); g_clear_error(&err); } if ( exit_status && !output ) { output = g_strdup_printf("<results><fatalerror message=\"Possible Compiler Crash.\" file=\"%s\" /></results>", args[0] ); } g_free(full_output_directory); g_free(args[0]); g_free(args[1]); g_free(args[2]); g_free(args[3]); g_free(args[4]); /* Check if compiler left an empty file */ entity_file = g_build_filename( AL_ProjectPath(), "c", input_file, NULL); compiled_entity_file = Meg_String_ReplaceFileExtension( entity_file, ".mps", ".amx" ); if ( file_get_size( compiled_entity_file ) == 0 ) { g_unlink(compiled_entity_file); } g_free(compiled_entity_file); g_free(entity_file); return output; }
/******************************** * Patch_ScanCurrent * @ store: @ game_files: */ void Patch_ScanCurrent( GtkListStore * store, GSList * game_files ) { GtkTreeIter children; gchar * directory_path, * file_path, * package_file; const gchar * current; GDir * directory; guint array_count = 0; gtk_list_store_clear( store ); if ( g_strv_length( mokoiPatchDirectories ) ) { while ( mokoiPatchDirectories[array_count] != NULL ) { directory_path = g_build_path( G_DIR_SEPARATOR_S, mokoiBasePath, mokoiPatchDirectories[array_count], NULL ); directory = g_dir_open( directory_path, 0, NULL); current = g_dir_read_name( directory ); while ( current != NULL ) { if ( current[0] != '.' ) { package_file = g_build_path( "/", mokoiPatchDirectories[array_count], current, NULL ); file_path = g_build_filename( directory_path, current, NULL ); if ( g_file_test( file_path, G_FILE_TEST_IS_REGULAR ) ) { gtk_list_store_append( store, &children ); gtk_list_store_set( store, &children, 0, Patch_HasChanged( game_files, package_file, file_get_size(file_path) ), 1, package_file, -1 ); } g_free( package_file ); g_free( file_path ); } current = g_dir_read_name( directory ); } g_dir_close( directory ); array_count++; } } }